@@ -333,16 +333,38 @@ function check_config($config_file) {
333333 $ config ->setServers ($ servers );
334334
335335 # Check the memory limit parameter.
336- if ((ini_get ('memory_limit ' ) > -1 ) && ini_get ('memory_limit ' ) < $ config ->getValue ('session ' ,'memorylimit ' ))
337- system_message (array (
338- 'title ' =>_ ('Memory Limit low. ' ),
339- 'body ' =>sprintf ('Your php memory limit is low - currently %s, you should increase it to atleast %s. This is normally controlled in /etc/php.ini. ' ,
340- ini_get ('memory_limit ' ),$ config ->getValue ('session ' ,'memorylimit ' )),
341- 'type ' =>'error ' ));
342-
336+ $ limit = memory_str_to_int (ini_get ('memory_limit ' ));
337+ if ($ limit != -1 ) {
338+ $ threshold = memory_str_to_int ($ config ->getValue ('session ' ,'memorylimit ' ));
339+ if ($ limit < $ threshold ) {
340+ system_message (array (
341+ 'title ' => _ ('Memory Limit low. ' ),
342+ 'body ' => sprintf ('Your php memory limit is low - currently %s (%s), you should increase it to atleast %s (%s). This is normally controlled in /etc/php.ini. ' ,
343+ ini_get ('memory_limit ' ), $ limit , $ config ->getValue ('session ' ,'memorylimit ' ), $ threshold ),
344+ 'type ' =>'error '
345+ ));
346+ }
347+ }
343348 return $ config ;
344349}
345350
351+ /**
352+ * Converts shorthand memory notation string to an integer that represents the
353+ * given amount in bytes (ie. "128M" -> 134217728).
354+ *
355+ * @param string|int $value
356+ * @return int
357+ */
358+ function memory_str_to_int ($ value ) {
359+ $ value = trim (strtolower ($ value ));
360+ if (intval ($ value ) > 0 && preg_match ('/^(\d+)([kmg])?$/ ' , $ value , $ match , PREG_UNMATCHED_AS_NULL )) {
361+ [$ int , $ mod ] = [intval ($ match [1 ]), $ match [2 ]];
362+ $ pow = [NULL => 0 , 'k ' => 1 , 'm ' => 2 , 'g ' => 3 ][$ mod ];
363+ return $ int * 1024 ** $ pow ;
364+ }
365+ return intval ($ value );
366+ }
367+
346368/**
347369 * Commands available in the control_panel of the page
348370 *
0 commit comments