* fix #165 : Handle shorthand notation for PHP memory_limit check * fix config default memory threshold.
This commit is contained in:
parent
364c0565a2
commit
15cc6f5382
@ -504,7 +504,7 @@ class Config {
|
|||||||
|
|
||||||
$this->default->session['memorylimit'] = array(
|
$this->default->session['memorylimit'] = array(
|
||||||
'desc'=>'Set the PHP memorylimit warning threshold.',
|
'desc'=>'Set the PHP memorylimit warning threshold.',
|
||||||
'default'=>24);
|
'default'=>'24M');
|
||||||
|
|
||||||
$this->default->session['timelimit'] = array(
|
$this->default->session['timelimit'] = array(
|
||||||
'desc'=>'Set the PHP timelimit.',
|
'desc'=>'Set the PHP timelimit.',
|
||||||
|
@ -333,16 +333,38 @@ function check_config($config_file) {
|
|||||||
$config->setServers($servers);
|
$config->setServers($servers);
|
||||||
|
|
||||||
# Check the memory limit parameter.
|
# Check the memory limit parameter.
|
||||||
if ((ini_get('memory_limit') > -1) && ini_get('memory_limit') < $config->getValue('session','memorylimit'))
|
$limit = memory_str_to_int(ini_get('memory_limit'));
|
||||||
system_message(array(
|
if ($limit != -1) {
|
||||||
'title'=>_('Memory Limit low.'),
|
$threshold = memory_str_to_int($config->getValue('session','memorylimit'));
|
||||||
'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.',
|
if ($limit < $threshold) {
|
||||||
ini_get('memory_limit'),$config->getValue('session','memorylimit')),
|
system_message(array(
|
||||||
'type'=>'error'));
|
'title' => _('Memory Limit low.'),
|
||||||
|
'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.',
|
||||||
|
ini_get('memory_limit'), $limit, $config->getValue('session','memorylimit'), $threshold),
|
||||||
|
'type'=>'error'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts shorthand memory notation string to an integer that represents the
|
||||||
|
* given amount in bytes (ie. "128M" -> 134217728).
|
||||||
|
*
|
||||||
|
* @param string|int $value
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
function memory_str_to_int($value) {
|
||||||
|
$value = trim(strtolower($value));
|
||||||
|
if (intval($value) > 0 && preg_match('/^(\d+)([kmg])?$/', $value, $match, PREG_UNMATCHED_AS_NULL)) {
|
||||||
|
[$int, $mod] = [intval($match[1]), $match[2]];
|
||||||
|
$pow = [NULL => 0, 'k' => 1, 'm' => 2, 'g' => 3][$mod];
|
||||||
|
return $int * 1024 ** $pow;
|
||||||
|
}
|
||||||
|
return intval($value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commands available in the control_panel of the page
|
* Commands available in the control_panel of the page
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user