Skip to content
Snippets Groups Projects
Commit 73038c47 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

Check memory settings on ?do

This should help with diagnosing memory related problems

darcs-hash:20080223180701-7ad00-1308829c3d7432b1d0c23c3f1acc8228c0a41e1e.gz
parent 7b3f8b16
No related branches found
No related tags found
No related merge requests found
......@@ -1135,4 +1135,31 @@ function unslash($string,$char="'"){
return str_replace('\\'.$char,$char,$string);
}
/**
* Convert php.ini shorthands to byte
*
* @author <gilthans dot NO dot SPAM at gmail dot com>
* @link http://de3.php.net/manual/en/ini.core.php#79564
*/
function php_to_byte($v){
$l = substr($v, -1);
$ret = substr($v, 0, -1);
switch(strtoupper($l)){
case 'P':
$ret *= 1024;
case 'T':
$ret *= 1024;
case 'G':
$ret *= 1024;
case 'M':
$ret *= 1024;
case 'K':
$ret *= 1024;
break;
}
return $ret;
}
//Setup VIM: ex: et ts=2 enc=utf-8 :
......@@ -89,6 +89,20 @@ function check(){
msg('PHP version '.phpversion(),1);
}
$mem = (int) php_to_byte(ini_get('memory_limit'));
if($mem){
if($mem < 16777216){
msg('PHP is limited to less than 16MB RAM ('.$mem.' bytes). Increase memory_limit in php.ini',-1);
}elseif($mem < 20971520){
msg('PHP is limited to less than 20MB RAM ('.$mem.' bytes), you might encounter problems with bigger pages. Increase memory_limit in php.ini',-1);
}elseif($mem < 33554432){
msg('PHP is limited to less than 32MB RAM ('.$mem.' bytes), but that should be enough in most cases. If not, increase memory_limit in php.ini',0);
}else{
msg('More than 32MB RAM ('.$mem.' bytes) available.',1);
}
}
if(is_writable($conf['changelog'])){
msg('Changelog is writable',1);
}else{
......
......@@ -425,7 +425,7 @@ function resize_imageGD($ext,$from,$from_w,$from_h,$to,$to_w,$to_h){
* Checks if the given amount of memory is available
*
* If the memory_get_usage() function is not available the
* function just assumes $used bytes of already allocated memory
* function just assumes $bytes of already allocated memory
*
* @param int $mem Size of memory you want to allocate in bytes
* @param int $used already allocated memory (see above)
......@@ -437,28 +437,13 @@ function is_mem_available($mem,$bytes=1048576){
if(empty($limit)) return true; // no limit set!
// parse limit to bytes
$unit = strtolower(substr($limit,-1));
switch($unit){
case 'g':
$limit = substr($limit,0,-1);
$limit *= 1024*1024*1024;
break;
case 'm':
$limit = substr($limit,0,-1);
$limit *= 1024*1024;
break;
case 'k':
$limit = substr($limit,0,-1);
$limit *= 1024;
break;
}
$limit = php_to_byte($limit);
// get used memory if possible
if(function_exists('memory_get_usage')){
$used = memory_get_usage();
}
if($used+$mem > $limit){
return false;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment