Skip to content

Commit 601717c

Browse files
Add simple kv storages in mysql and pgsql
1 parent 6cc136c commit 601717c

17 files changed

+804
-4
lines changed

‎bench.php

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Author : Sergey Dryabzhinsky #
1111
# Company : Rusoft Ltd, Russia #
1212
# Date : Jun 7, 2025 #
13-
# Version : 1.0.65 #
13+
# Version : 1.0.66-dev #
1414
# License : Creative Commons CC-BY license #
1515
# Website : https://github.com/rusoft/php-simple-benchmark-script #
1616
# Website : https://gitea.rusoft.ru/open-source/php-simple-benchmark-script #
@@ -20,7 +20,7 @@
2020

2121
include_once("php-options.php");
2222

23-
$scriptVersion = '1.0.65';
23+
$scriptVersion = '1.0.66-dev';
2424

2525
// Special string to flush buffers, nginx for example
2626
$flushStr = '<!-- '.str_repeat(" ", 8192).' -->';
@@ -134,6 +134,19 @@
134134
if (file_exists('kvstorage-redis.inc') && extension_loaded('redis')) {
135135
@include_once("kv-redis.inc");
136136
}
137+
if (file_exists('kvstorage-pgsql.inc') && extension_loaded('pgsql')) {
138+
@include_once("kv-pgsql.inc");
139+
}
140+
if (file_exists('kvstorage-mysql.inc') && extension_loaded('mysql')) {
141+
@include_once("kv-mysql-myisam.inc");
142+
@include_once("kv-mysql-innodb.inc");
143+
@include_once("kv-mysql-memory.inc");
144+
}
145+
if (file_exists('kvstorage-mysqli.inc') && extension_loaded('mysqli')) {
146+
@include_once("kv-mysqli-myisam.inc");
147+
@include_once("kv-mysqli-innodb.inc");
148+
@include_once("kv-mysqli-memory.inc");
149+
}
137150
}// php>=5.0
138151
if ( PHP_VERSION >= '5.3.0') {
139152
if (file_exists('kvstorage-sqlite3.inc') && extension_loaded('sqlite3')) {
@@ -846,6 +859,13 @@ function gethostname() {
846859
'42_ctype_isdigit' => 10000000,
847860
'43_iconv_translit' => 10000000,
848861
'44_session_time' => 100000,
862+
'45_01_kvs_mysql_myisam' => 1000000,
863+
'45_02_kvs_mysql_innodb' => 1000000,
864+
'45_03_kvs_mysql_memory' => 1000000,
865+
'46_01_kvs_mysqli_myisam' => 1000000,
866+
'46_02_kvs_mysqli_innodb' => 1000000,
867+
'46_03_kvs_mysqli_memory' => 1000000,
868+
'47_kvs_pgsql' => 100000,
849869
);
850870
// Should not be more than X Mb
851871
// Different PHP could use different amount of memory
@@ -923,6 +943,13 @@ function gethostname() {
923943
'42_ctype_isdigit' => 4,
924944
'43_iconv_translit' => 4,
925945
'44_session_time' => 4,
946+
'45_01_kvs_mysql_myisam' => 4,
947+
'45_02_kvs_mysql_innodb' => 4,
948+
'45_03_kvs_mysql_memory' => 4,
949+
'46_01_kvs_mysqli_myisam' => 4,
950+
'46_02_kvs_mysqli_innodb' => 4,
951+
'46_03_kvs_mysqli_memory' => 4,
952+
'47_kvs_pgsql' => 4,
926953
);
927954

928955
/** ---------------------------------- Common functions -------------------------------------------- */
@@ -1753,6 +1780,30 @@ function filter_out_name_by_pattern($key)
17531780
if ($v) define('REDIS_VERSION',$v);
17541781
else define('REDIS_VERSION','-.-.-');
17551782
}
1783+
$has_mysql = "{$colorYellow}no{$colorReset}";
1784+
if (extension_loaded('mysql')) {
1785+
$has_mysql = "{$colorGreen}yes{$colorReset}";
1786+
include_once('mysql.inc');
1787+
$v=get_mysql_version();
1788+
if ($v) define('MYSQL_VERSION',$v);
1789+
else define('MYSQL_VERSION','-.-.-');
1790+
}
1791+
$has_pgsql = "{$colorYellow}no{$colorReset}";
1792+
if (extension_loaded('pgsql')) {
1793+
$has_pgsql = "{$colorGreen}yes{$colorReset}";
1794+
include_once('pgsql.inc');
1795+
$v=get_pgsql_version();
1796+
if ($v) define('PGSQL_VERSION',$v);
1797+
else define('PGSQL_VERSION','-.-.-');
1798+
}
1799+
$has_mysqli = "{$colorYellow}no{$colorReset}";
1800+
if (extension_loaded('mysqli')) {
1801+
$has_mysqli = "{$colorGreen}yes{$colorReset}";
1802+
include_once('mysqli.inc');
1803+
$v=get_mysqli_version();
1804+
if ($v) define('MYSQLI_VERSION',$v);
1805+
else define('MYSQLI_VERSION','-.-.-');
1806+
}
17561807
$has_sqlite3 = "{$colorYellow}no{$colorReset}";
17571808
if (extension_loaded('sqlite3')) {
17581809
$has_sqlite3 = "{$colorGreen}yes{$colorReset}";
@@ -1886,6 +1937,8 @@ function filter_out_name_by_pattern($key)
18861937
if (!defined('MEMCACHE_VERSION')) define('MEMCACHE_VERSION', '-.-.-');
18871938
if (!defined('REDIS_VERSION')) define('REDIS_VERSION', '-.-.-');
18881939
if (!defined('SQLITE3_VERSION')) define('SQLITE3_VERSION', '-.-.-');
1940+
if (!defined('MYSQL_VERSION')) define('MYSQL_VERSION', '-.-.-');
1941+
if (!defined('MYSQLI_VERSION')) define('MYSQLI_VERSION', '-.-.-');
18891942
if (!defined('LIBXML_DOTTED_VERSION')) define('LIBXML_DOTTED_VERSION', '-.-.-');
18901943
if (!defined('SODIUM_LIBRARY_VERSION')) define('SODIUM_LIBRARY_VERSION', '-.-.-');
18911944
if (!defined('INTL_ICU_VERSION')) define('INTL_ICU_VERSION', '-.-');
@@ -1901,7 +1954,7 @@ function print_results_common()
19011954
global $has_gd, $has_gdgif, $has_gdpng, $has_gdjpg, $has_gdwebp, $has_gdavif;
19021955
global $has_imagick, $has_igb, $has_msg, $has_jsond, $has_jsond_as_json, $has_ctype, $has_iconv, $has_session;
19031956
global $has_zlib, $has_uuid, $has_gzip, $has_bz2, $has_lz4, $has_snappy, $has_zstd, $has_brotli;
1904-
global $has_apcu, $has_shmop, $has_memcache, $has_redis, $has_sodium, $has_sqlite3, $opcache, $has_eacc, $has_xdebug, $xcache, $apcache, $eaccel, $xdebug, $xdbg_mode, $obd_set, $mbover;
1957+
global $has_apcu, $has_shmop, $has_memcache, $has_redis, $has_mysql, $has_pgsql, $has_mysqli, $has_sodium, $has_sqlite3, $opcache, $has_eacc, $has_xdebug, $xcache, $apcache, $eaccel, $xdebug, $xdbg_mode, $obd_set, $mbover;
19051958
global $showOnlySystemInfo, $padLabel, $functions, $runOnlySelectedTests, $selectedTests, $totalOps;
19061959
global $colorGreen, $colorReset, $colorRed;
19071960

@@ -1944,11 +1997,14 @@ function print_results_common()
19441997
. str_pad("\t- JPG", $padInfo, ' ', STR_PAD_LEFT) . " : $has_gdjpg"."\n"
19451998
. str_pad("\t- WEBP", $padInfo, ' ', STR_PAD_LEFT) . " : $has_gdwebp"."\n"
19461999
. str_pad("\t- AVIF", $padInfo, ' ', STR_PAD_LEFT) . " : $has_gdavif"."\n"
1947-
. str_pad("imagick", $padInfo, ' ', STR_PAD_LEFT) . " : $has_imagick: version: ".IMG_VERSION."\n"
2000+
. str_pad("imagick", $padInfo, ' ', STR_PAD_LEFT) . " : $has_imagick: version: ".IMG_VERSION.";\n"
19482001
. str_pad("apcu", $padInfo, ' ', STR_PAD_LEFT) . " : $has_apcu;\n"
19492002
. str_pad("shmop", $padInfo, ' ', STR_PAD_LEFT) . " : $has_shmop\n"
19502003
. str_pad("memcache", $padInfo, ' ', STR_PAD_LEFT) . " : $has_memcache, version: ".MEMCACHE_VERSION.";\n"
19512004
. str_pad("redis", $padInfo, ' ', STR_PAD_LEFT) . " : $has_redis, version: ".REDIS_VERSION.";\n"
2005+
. str_pad("mysql", $padInfo, ' ', STR_PAD_LEFT) . " : $has_mysql, version: ".MYSQL_VERSION.";\n"
2006+
. str_pad("pgsql", $padInfo, ' ', STR_PAD_LEFT) . " : $has_pgsql, version: ".PGSQL_VERSION.";\n"
2007+
. str_pad("mysqli", $padInfo, ' ', STR_PAD_LEFT) . " : $has_mysqli, version: ".MYSQLI_VERSION.";\n"
19522008
. str_pad("sqlite3", $padInfo, ' ', STR_PAD_LEFT) . " : $has_sqlite3, version: ".SQLITE3_VERSION.";\n"
19532009
. str_pad("sodium", $padInfo, ' ', STR_PAD_LEFT) . " : $has_sodium, version: ".SODIUM_LIBRARY_VERSION.";\n"
19542010
. str_pad("-alternative->", $padInfo, ' ', STR_PAD_LEFT) . "\n"

‎kv-mysql-innodb.inc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* php safe options - only tests mod mysql
4+
* Php 4.0+
5+
*/
6+
7+
/** ---------------------------------- Tests functions -------------------------------------------- */
8+
9+
// ------------------------- INTL tests -----------------------
10+
11+
/**
12+
* @since 4.0
13+
*/
14+
function test_45_02_kvs_mysql_innodb()
15+
{
16+
global $testsLoopLimits, $totalOps, $emptyResult;
17+
global $sqlite3_dbpath, $debugMode;
18+
19+
if (!is_file('kvstorage-mysql.inc')){
20+
print("storage no file");
21+
return $emptyResult;
22+
}
23+
if (!function_exists('mysql_query')){
24+
ptint("no func");
25+
return $emptyResult;
26+
}
27+
28+
include_once('kvstorage-mysql.inc');
29+
$kvstorage=new KVStorageMysql();
30+
$kvstorage->engineName='INNOdb';
31+
$kvstorage->open();
32+
$kvstorage->drop();
33+
$kvstorage->create();
34+
if (!$kvstorage->available){
35+
print("storage noavail");
36+
return $emptyResult;
37+
}
38+
39+
$count = $testsLoopLimits['45_02_kvs_mysql_innodb'];
40+
$time_start = get_microtime();
41+
42+
for ($i = 0; $i < $count; $i++) {
43+
$num = $i / 100.;
44+
$kvstorage->set($i, $num);
45+
$v=$kvstorage->get($i);
46+
$kvstorage->del($i);
47+
}
48+
$kvstorage->close();
49+
$totalOps += $count;
50+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
51+
}

‎kv-mysql-memory.inc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* php safe options - only tests mod mysql
4+
* Php 4.0+
5+
*/
6+
7+
/** ---------------------------------- Tests functions -------------------------------------------- */
8+
9+
// ------------------------- INTL tests -----------------------
10+
11+
/**
12+
* @since 4.0
13+
*/
14+
function test_45_03_kvs_mysql_memory()
15+
{
16+
global $testsLoopLimits, $totalOps, $emptyResult;
17+
global $sqlite3_dbpath, $debugMode;
18+
19+
if (!is_file('kvstorage-mysql.inc')){
20+
print("storage no file");
21+
return $emptyResult;
22+
}
23+
if (!function_exists('mysql_query')){
24+
ptint("no func");
25+
return $emptyResult;
26+
}
27+
28+
include_once('kvstorage-mysql.inc');
29+
$kvstorage=new KVStorageMysql();
30+
$kvstorage->engineName='MEMORY';
31+
$kvstorage->open();
32+
$kvstorage->drop();
33+
$kvstorage->create();
34+
if (!$kvstorage->available){
35+
print("storage noavail");
36+
return $emptyResult;
37+
}
38+
39+
$count = $testsLoopLimits['45_03_kvs_mysql_memory'];
40+
$time_start = get_microtime();
41+
42+
for ($i = 0; $i < $count; $i++) {
43+
$num = $i / 100.;
44+
$kvstorage->set($i, $num);
45+
$v=$kvstorage->get($i);
46+
$kvstorage->del($i);
47+
}
48+
$kvstorage->close();
49+
$totalOps += $count;
50+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
51+
}

‎kv-mysql-myisam.inc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* php safe options - only tests mod mysql
4+
* Php 4.0+
5+
*/
6+
7+
/** ---------------------------------- Tests functions -------------------------------------------- */
8+
9+
// ------------------------- INTL tests -----------------------
10+
11+
/**
12+
* @since 4.0
13+
*/
14+
function test_45_01_kvs_mysql_myisam()
15+
{
16+
global $testsLoopLimits, $totalOps, $emptyResult;
17+
global $sqlite3_dbpath, $debugMode;
18+
19+
if (!is_file('kvstorage-mysql.inc')){
20+
print("storage no file");
21+
return $emptyResult;
22+
}
23+
if (!function_exists('mysql_query')){
24+
ptint("no func");
25+
return $emptyResult;
26+
}
27+
28+
include_once('kvstorage-mysql.inc');
29+
$kvstorage=new KVStorageMysql();
30+
$kvstorage->engineName='MyISAM';
31+
$kvstorage->open();
32+
$kvstorage->drop();
33+
$kvstorage->create();
34+
if (!$kvstorage->available){
35+
print("storage noavail");
36+
return $emptyResult;
37+
}
38+
39+
$count = $testsLoopLimits['45_01_kvs_mysql_myisam'];
40+
$time_start = get_microtime();
41+
42+
for ($i = 0; $i < $count; $i++) {
43+
$num = $i / 100.;
44+
$kvstorage->set($i, $num);
45+
$v=$kvstorage->get($i);
46+
$kvstorage->del($i);
47+
}
48+
$kvstorage->close();
49+
$totalOps += $count;
50+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
51+
}

‎kv-mysqli-innodb.inc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* php safe options - only tests mod mysqli
4+
* Php 4.0+
5+
*/
6+
7+
/** ---------------------------------- Tests functions -------------------------------------------- */
8+
9+
// ------------------------- INTL tests -----------------------
10+
11+
/**
12+
* @since 4.0
13+
*/
14+
function test_46_02_kvs_mysqli_innodb()
15+
{
16+
global $testsLoopLimits, $totalOps, $emptyResult;
17+
global $sqlite3_dbpath, $debugMode;
18+
19+
if (!is_file('kvstorage-mysqli.inc')){
20+
print("storage no file");
21+
return $emptyResult;
22+
}
23+
if (!function_exists('mysqli_query')){
24+
ptint("no func");
25+
return $emptyResult;
26+
}
27+
28+
include_once('kvstorage-mysqli.inc');
29+
$kvstorage=new KVStorageMysqli();
30+
$kvstorage->engineName='INNOdb';
31+
$kvstorage->open();
32+
$kvstorage->drop();
33+
$kvstorage->create();
34+
if (!$kvstorage->available){
35+
print("storage noavail");
36+
return $emptyResult;
37+
}
38+
39+
$count = $testsLoopLimits['46_02_kvs_mysqli_innodb'];
40+
$time_start = get_microtime();
41+
42+
for ($i = 1; $i < $count; $i++) {
43+
$num =number_format( $i / 100., 2, '.', '');
44+
$kvstorage->set($i, $num);
45+
$v=$kvstorage->get($i);
46+
$kvstorage->del($i);
47+
}
48+
$kvstorage->close();
49+
$totalOps += $count;
50+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
51+
}

‎kv-mysqli-memory.inc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* php safe options - only tests mod mysqli
4+
* Php 4.0+
5+
*/
6+
7+
/** ---------------------------------- Tests functions -------------------------------------------- */
8+
9+
// ------------------------- INTL tests -----------------------
10+
11+
/**
12+
* @since 4.0
13+
*/
14+
function test_46_03_kvs_mysqli_memory()
15+
{
16+
global $testsLoopLimits, $totalOps, $emptyResult;
17+
global $sqlite3_dbpath, $debugMode;
18+
19+
if (!is_file('kvstorage-mysqli.inc')){
20+
print("storage no file");
21+
return $emptyResult;
22+
}
23+
if (!function_exists('mysqli_query')){
24+
ptint("no func");
25+
return $emptyResult;
26+
}
27+
28+
include_once('kvstorage-mysqli.inc');
29+
$kvstorage=new KVStorageMysqli();
30+
$kvstorage->engineName='MEMORY';
31+
$kvstorage->open();
32+
$kvstorage->drop();
33+
$kvstorage->create();
34+
if (!$kvstorage->available){
35+
print("storage noavail");
36+
return $emptyResult;
37+
}
38+
39+
$count = $testsLoopLimits['46_03_kvs_mysqli_memory'];
40+
$time_start = get_microtime();
41+
42+
for ($i = 1; $i < $count; $i++) {
43+
$num = number_format($i / 100., 2, '.', '');
44+
$kvstorage->set($i, $num);
45+
$v=$kvstorage->get($i);
46+
$kvstorage->del($i);
47+
}
48+
$kvstorage->close();
49+
$totalOps += $count;
50+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
51+
}

0 commit comments

Comments
 (0)