11<?php
22/*
3- Version 1.2
4- Copyright 2012-2015 - Amaury Balmer ([email protected] ) 3+ Version 1.3
4+ Copyright 2012-2016 - Amaury Balmer ([email protected] ) 55
66This program is free software; you can redistribute it and/or modify
77it under the terms of the GNU General Public License, version 2, as
@@ -309,12 +309,12 @@ public function test_php_config() {
309309 $ this ->html_table_row ( 'register_argc_argv ' , '- ' , 'Off ' , 'Off ' , 'success ' );
310310 }
311311
312- $ value = ini_get ( 'memory_limit ' );
313- if ( intval ( $ value ) < 64 ) {
314- $ this ->html_table_row ( 'memory_limit ' , '64M ' , '256M ' , $ value , 'error ' );
312+ $ value = $ this -> return_bytes ( ini_get ( 'memory_limit ' ) );
313+ if ( intval ( $ value ) < $ this -> return_bytes ( ' 64M ' ) ) {
314+ $ this ->html_table_row ( 'memory_limit ' , '64 MB ' , '256 MB ' , $ this -> _format_bytes ( $ value) , 'error ' );
315315 } else {
316- $ status = (intval ( $ value ) >= ( 8388608 * 32 )) ? 'success ' : 'warning ' ; // 256mb
317- $ this ->html_table_row ( 'memory_limit ' , '64M ' , '256M ' , $ value , $ status );
316+ $ status = (intval ( $ value ) >= $ this -> return_bytes ( ' 256M ' )) ? 'success ' : 'warning ' ;
317+ $ this ->html_table_row ( 'memory_limit ' , '64 MB ' , '256 MB ' , $ this -> _format_bytes ( $ value) , $ status );
318318 }
319319
320320 $ value = ini_get ( 'max_input_vars ' );
@@ -332,20 +332,20 @@ public function test_php_config() {
332332 $ this ->html_table_row ( 'file_uploads ' , 'On ' , 'On ' , 'Off ' , 'error ' );
333333 }
334334
335- $ value = ini_get ( 'upload_max_filesize ' );
336- if ( intval ( $ value ) < 32 ) {
337- $ this ->html_table_row ( 'upload_max_filesize ' , '32M ' , '128M ' , $ value , 'warning ' );
335+ $ value = $ this -> return_bytes ( ini_get ( 'upload_max_filesize ' ) );
336+ if ( intval ( $ value ) < $ this -> return_bytes ( ' 32M ' ) ) {
337+ $ this ->html_table_row ( 'upload_max_filesize ' , '32 MB ' , '128 MB ' , $ this -> _format_bytes ( $ value) , 'error ' );
338338 } else {
339- $ status = (intval ( $ value ) >= ( 8388608 * 8 )) ? 'success ' : 'warning ' ; // 128mb
340- $ this ->html_table_row ( 'upload_max_filesize ' , '32M ' , '128M ' , $ value , $ status );
339+ $ status = (intval ( $ value ) >= $ this -> return_bytes ( ' 128M ' )) ? 'success ' : 'warning ' ;
340+ $ this ->html_table_row ( 'upload_max_filesize ' , '32 MB ' , '128 MB ' , $ this -> _format_bytes ( $ value) , $ status );
341341 }
342342
343- $ value = ini_get ( 'post_max_size ' );
344- if ( intval ( $ value ) < 32 ) {
345- $ this ->html_table_row ( 'post_max_size ' , '32M ' , '128M ' , $ value , 'warning ' );
343+ $ value = $ this -> return_bytes ( ini_get ( 'post_max_size ' ) );
344+ if ( intval ( $ value ) < $ this -> return_bytes ( ' 32M ' ) ) {
345+ $ this ->html_table_row ( 'post_max_size ' , '32 MB ' , '128 MB ' , $ this -> _format_bytes ( $ value) , 'warning ' );
346346 } else {
347- $ status = (intval ( $ value ) >= ( 8388608 * 8 )) ? 'success ' : 'warning ' ; // 128mb
348- $ this ->html_table_row ( 'post_max_size ' , '32M ' , '128M ' , $ value , $ status );
347+ $ status = (intval ( $ value ) >= $ this -> return_bytes ( ' 128M ' )) ? 'success ' : 'warning ' ;
348+ $ this ->html_table_row ( 'post_max_size ' , '32 MB ' , '128 MB ' , $ this -> _format_bytes ( $ value) , $ status );
349349 }
350350
351351 $ value = ini_get ( 'short_open_tag ' );
@@ -403,18 +403,39 @@ public function test_php_config() {
403403 }
404404
405405 if ( is_callable ( 'apc_store ' ) ) {
406- $ value = ini_get ( 'apc.shm_size ' );
407- if ( intval ( $ value ) < 32 ) {
408- $ this ->html_table_row ( 'apc.shm_size ' , '32M ' , '128M ' , $ value , 'error ' );
406+ $ value = $ this -> return_bytes ( ini_get ( 'apc.shm_size ' ) );
407+ if ( intval ( $ value ) < $ this -> return_bytes ( ' 32M ' ) ) {
408+ $ this ->html_table_row ( 'apc.shm_size ' , '32 MB ' , '128 MB ' , $ this -> _format_bytes ( $ value) , 'error ' );
409409 } else {
410- $ status = (intval ( $ value ) >= ( 8388608 * 16 )) ? 'success ' : 'warning ' ; // 128mb
411- $ this ->html_table_row ( 'apc.shm_size ' , '32M ' , '128M ' , $ value , $ status );
410+ $ status = (intval ( $ value ) >= $ this -> return_bytes ( ' 128M ' )) ? 'success ' : 'warning ' ;
411+ $ this ->html_table_row ( 'apc.shm_size ' , '32 MB ' , '128 MB ' , $ this -> _format_bytes ( $ value) , $ status );
412412 }
413413 }
414414
415415 $ this ->html_table_close ();
416416 }
417417
418+ /**
419+ * Convert PHP variable (G/M/K) to bytes
420+ * Source: http://php.net/manual/fr/function.ini-get.php
421+ *
422+ */
423+ public function return_bytes ($ val ) {
424+ $ val = trim ($ val );
425+ $ last = strtolower ($ val [strlen ($ val )-1 ]);
426+ switch ($ last ) {
427+ // Le modifieur 'G' est disponible depuis PHP 5.1.0
428+ case 'g ' :
429+ $ val *= 1024 ;
430+ case 'm ' :
431+ $ val *= 1024 ;
432+ case 'k ' :
433+ $ val *= 1024 ;
434+ }
435+
436+ return $ val ;
437+ }
438+
418439 /**
419440 * @return bool
420441 */
@@ -439,8 +460,8 @@ public function test_mysqli_config() {
439460 $ result = mysqli_query ( $ this ->db_link , "SHOW VARIABLES LIKE 'query_cache_size' " );
440461 if ( $ result != false ) {
441462 while ( $ row = mysqli_fetch_assoc ( $ result ) ) {
442- if ( intval ( $ row ['Value ' ] ) >= 8388608 ) { // 8mb
443- $ status = (intval ( $ row ['Value ' ] ) >= ( 8388608 * 8 )) ? 'success ' : 'warning ' ; // 64mb
463+ if ( intval ( $ row ['Value ' ] ) >= $ this -> return_bytes ( ' 8M ' ) ) {
464+ $ status = (intval ( $ row ['Value ' ] ) >= $ this -> return_bytes ( ' 64M ' )) ? 'success ' : 'warning ' ;
444465 $ this ->html_table_row ( "Query cache size " , '8M ' , '64MB ' , $ this ->_format_bytes ( (int ) $ row ['Value ' ] ), $ status );
445466 } else {
446467 $ this ->html_table_row ( "Query cache size " , '8M ' , '64MB ' , $ this ->_format_bytes ( (int ) $ row ['Value ' ] ), 'error ' );
0 commit comments