10
10
# Author : Sergey Dryabzhinsky #
11
11
# Company : Rusoft Ltd, Russia #
12
12
# Date : Dec 05, 2021 #
13
- # Version : 1.0.44 #
13
+ # Version : 1.0.45-dev #
14
14
# License : Creative Commons CC-BY license #
15
15
# Website : https://github.com/rusoft/php-simple-benchmark-script #
16
16
# Website : https://git.rusoft.ru/open-source/php-simple-benchmark-script #
@@ -32,10 +32,10 @@ function print_pre($msg) {
32
32
flush ();
33
33
}
34
34
35
- $ scriptVersion = '1.0.44 ' ;
35
+ $ scriptVersion = '1.0.45-dev ' ;
36
36
37
37
// Special string to flush buffers, nginx for example
38
- $ flushStr = '<!-- ' .str_repeat (" " , 4096 ).' --> ' ;
38
+ $ flushStr = '<!-- ' .str_repeat (" " , 8192 ).' --> ' ;
39
39
40
40
if (php_sapi_name () != 'cli ' ) {
41
41
// Hello, nginx!
@@ -121,6 +121,8 @@ function print_pre($msg) {
121
121
/* Default PHP memory limit in Mb */
122
122
$ defaultMemoryLimit = 256 ;
123
123
124
+ $ debugMode = 0 ;
125
+
124
126
$ recalculateLimits = 1 ;
125
127
126
128
$ printDumbTest = 0 ;
@@ -140,6 +142,13 @@ function print_pre($msg) {
140
142
$ defaultTimeLimit = $ t ;
141
143
}
142
144
145
+ if ($ x = (int )getenv ('PHP_DEBUG_MODE ' )) {
146
+ $ debugMode = $ x ;
147
+ }
148
+ if (isset ($ _GET ['debug_mode ' ]) && $ x = (int )$ _GET ['debug_mode ' ]) {
149
+ $ debugMode = $ x ;
150
+ }
151
+
143
152
if ($ m = (int )getenv ('PHP_MEMORY_LIMIT ' )) {
144
153
$ defaultMemoryLimit = $ m ;
145
154
}
@@ -189,8 +198,10 @@ function print_pre($msg) {
189
198
$ selectedTests = explode (', ' , $ _GET ['run_tests ' ]);
190
199
}
191
200
201
+
192
202
// http://php.net/manual/ru/function.getopt.php example #2
193
203
$ shortopts = "h " ;
204
+ $ shortopts .= "x " ;
194
205
$ shortopts .= "d " ;
195
206
$ shortopts .= "D " ;
196
207
$ shortopts .= "L " ;
@@ -202,6 +213,7 @@ function print_pre($msg) {
202
213
203
214
$ longopts = array (
204
215
"help " ,
216
+ "debug " ,
205
217
"dont-recalc " ,
206
218
"dumb-test-print " ,
207
219
"list-tests " ,
@@ -238,6 +250,7 @@ function print_pre($msg) {
238
250
. 'Usage: ' . basename (__FILE__ ) . ' [-h|--help] [-d|--dont-recalc] [-D|--dumb-test-print] [-L|--list-tests] [-I|--system-info] [-S|--do-not-task-set] [-m|--memory-limit=256] [-t|--time-limit=600] [-T|--run-test=name1 ...] ' . PHP_EOL
239
251
. PHP_EOL
240
252
. ' -h|--help - print this help and exit ' . PHP_EOL
253
+ . ' -x|--debug - enable debug mode, raise output level ' . PHP_EOL
241
254
. ' -d|--dont-recalc - do not recalculate test times / operations count even if memory of execution time limits are low ' . PHP_EOL
242
255
. ' -D|--dumb-test-print - print dumb test time, for debug purpose ' . PHP_EOL
243
256
. ' -L|--list-tests - output list of available tests and exit ' . PHP_EOL
@@ -258,6 +271,7 @@ function print_pre($msg) {
258
271
. 'Usage: ' . basename (__FILE__ ) . ' [-h] [-d] [-D] [-L] [-I] [-S] [-m 256] [-t 600] [-T name1 ...] ' . PHP_EOL
259
272
. PHP_EOL
260
273
. ' -h - print this help and exit ' . PHP_EOL
274
+ . ' -x - enable debug mode, raise output level ' . PHP_EOL
261
275
. ' -d - do not recalculate test times / operations count even if memory of execution time limits are low ' . PHP_EOL
262
276
. ' -D - print dumb test time, for debug purpose ' . PHP_EOL
263
277
. ' -L - output list of available tests and exit ' . PHP_EOL
@@ -288,6 +302,11 @@ function print_pre($msg) {
288
302
$ recalculateLimits = 0 ;
289
303
break ;
290
304
305
+ case 'x ' :
306
+ case 'debug ' :
307
+ $ debugMode = 1 ;
308
+ break ;
309
+
291
310
case 'D ' :
292
311
case 'dumb-test-print ' :
293
312
$ printDumbTest = 1 ;
@@ -523,9 +542,17 @@ function convert_si($size)
523
542
*/
524
543
function getPhpMemoryLimitBytes ()
525
544
{
545
+ global $ debugMode ;
526
546
// http://stackoverflow.com/a/10209530
527
547
$ memory_limit = strtolower (ini_get ('memory_limit ' ));
548
+ if ($ debugMode ) {
549
+ print_pre ("<<< DEBUG >>> getPhpMemoryLimitBytes(): ini_get memory_limit = ' {$ memory_limit }' \n" );
550
+ }
528
551
if (preg_match ('/^(\d+)(.)$/ ' , $ memory_limit , $ matches )) {
552
+ if ($ debugMode ) {
553
+ $ ve = var_export ($ matches , true );
554
+ print_pre ("<<< DEBUG >>> getPhpMemoryLimitBytes(): parse via preg_math: \n{$ ve }\n" );
555
+ }
529
556
if ($ matches [2 ] == 'g ' ) {
530
557
$ memory_limit = intval ($ matches [1 ]) * 1024 * 1024 * 1024 ; // nnnG -> nnn GB
531
558
} else if ($ matches [2 ] == 'm ' ) {
@@ -536,6 +563,9 @@ function getPhpMemoryLimitBytes()
536
563
$ memory_limit = intval ($ matches [1 ]); // nnn -> nnn B
537
564
}
538
565
}
566
+ if ($ debugMode ) {
567
+ print_pre ("<<< DEBUG >>> getPhpMemoryLimitBytes(): result memory_limit = ' {$ memory_limit }' \n" );
568
+ }
539
569
return $ memory_limit ;
540
570
}
541
571
@@ -568,10 +598,23 @@ function getSystemMemInfo()
568
598
*/
569
599
function getSystemMemoryFreeLimitBytes ()
570
600
{
601
+ global $ debugMode ;
571
602
$ info = getSystemMemInfo ();
603
+
604
+ if ($ debugMode ) {
605
+ $ ve = var_export ($ info , true );
606
+ print_pre ("<<< DEBUG >>> getSystemMemoryFreeLimitBytes(): system memory info: \n{$ ve }' \n" );
607
+ }
608
+
572
609
if (isset ($ info ['MemAvailable ' ])) {
610
+ if ($ debugMode ) {
611
+ print_pre ("<<< DEBUG >>> getSystemMemoryFreeLimitBytes(): return MemAvailable \n" );
612
+ }
573
613
return $ info ['MemAvailable ' ];
574
614
}
615
+ if ($ debugMode ) {
616
+ print_pre ("<<< DEBUG >>> getSystemMemoryFreeLimitBytes(): return MemFree + Cached + Buffers \n" );
617
+ }
575
618
return $ info ['MemFree ' ] + $ info ['Cached ' ] + $ info ['Buffers ' ];
576
619
}
577
620
@@ -824,8 +867,17 @@ function mymemory_usage()
824
867
}
825
868
}
826
869
827
- $ memoryLimit = min (getPhpMemoryLimitBytes (), getSystemMemoryFreeLimitBytes ());
870
+ $ memoryLimitPhp = getPhpMemoryLimitBytes ();
871
+ $ memoryLimitSystem = getSystemMemoryFreeLimitBytes ();
872
+ if ($ debugMode ) {
873
+ print_pre ("<<< DEBUG >>> Available memory in system: " . convert ($ memoryLimitSystem ) . PHP_EOL );
874
+ print_pre ("<<< DEBUG >>> Available memory for php : " . convert ($ memoryLimitPhp ) . PHP_EOL );
875
+ }
876
+ $ memoryLimit = min ($ memoryLimitPhp , $ memoryLimitSystem );
828
877
$ memoryLimitMb = convert ($ memoryLimit );
878
+ if ($ debugMode ) {
879
+ print_pre ("<<< DEBUG >>> Selected memory for php : " . $ memoryLimitMb . PHP_EOL );
880
+ }
829
881
830
882
// Adjust array tests limits
831
883
if ($ memoryLimit < $ testMemoryFull ) {
@@ -834,6 +886,10 @@ function mymemory_usage()
834
886
. " is less than minimum required: " . convert ($ testMemoryFull )
835
887
. ". \n Recalculate tests parameters to fit in memory limits. "
836
888
. "\n$ line " . PHP_EOL );
889
+ if ($ debugMode ) {
890
+ print_pre ("<<< DEBUG >>> Original memory limit for php : " . convert ($ originMemoryLimit ) . PHP_EOL );
891
+ print_pre ("<<< DEBUG >>> Calculated memory limit for php: " . convert ($ defaultMemoryLimit ) . PHP_EOL );
892
+ }
837
893
838
894
$ factor = 1.0 * ($ testMemoryFull - $ memoryLimit ) / $ testMemoryFull ;
839
895
0 commit comments