mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
raise_memory_limit() earlier -- resolves OOM on 64-bit platforms
On 64-bit platforms the in-memory footprint of our libraries is quite a bit larger than usual, and we hit the 8MB default memory limit before we call raise_memory_limit(). This patch moves raise_memory_limit() and get_realsize() to setuplib so we can call them earlier, and moves the call to _before_ we include the libraries. On AMD64, for MOODLE_17_STABLE the footprint is about 9.5MB. Diet time? :-)
This commit is contained in:
parent
b8d4068893
commit
76f3815be9
3 changed files with 68 additions and 71 deletions
|
@ -4014,34 +4014,6 @@ function get_directory_size($rootdir, $excludefile='') {
|
|||
return $size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts numbers like 10M into bytes.
|
||||
*
|
||||
* @param mixed $size The size to be converted
|
||||
* @return mixed
|
||||
*/
|
||||
function get_real_size($size=0) {
|
||||
if (!$size) {
|
||||
return 0;
|
||||
}
|
||||
$scan['MB'] = 1048576;
|
||||
$scan['Mb'] = 1048576;
|
||||
$scan['M'] = 1048576;
|
||||
$scan['m'] = 1048576;
|
||||
$scan['KB'] = 1024;
|
||||
$scan['Kb'] = 1024;
|
||||
$scan['K'] = 1024;
|
||||
$scan['k'] = 1024;
|
||||
|
||||
while (list($key) = each($scan)) {
|
||||
if ((strlen($size)>strlen($key))&&(substr($size, strlen($size) - strlen($key))==$key)) {
|
||||
$size = substr($size, 0, strlen($size) - strlen($key)) * $scan[$key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts bytes into display form
|
||||
*
|
||||
|
@ -4829,43 +4801,6 @@ function document_file($file, $include=true) {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to raise the memory limit to a new value.
|
||||
* Will respect the memory limit if it is higher, thus allowing
|
||||
* settings in php.ini, apache conf or command line switches
|
||||
* to override it
|
||||
*
|
||||
* The memory limit should be expressed with a string (eg:'64M')
|
||||
*
|
||||
* @param string $newlimit the new memory limit
|
||||
* @return bool
|
||||
*/
|
||||
function raise_memory_limit ($newlimit) {
|
||||
|
||||
if (empty($newlimit)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cur = @ini_get('memory_limit');
|
||||
if (empty($cur)) {
|
||||
// if php is compiled without --enable-memory-limits
|
||||
// apparently memory_limit is set to ''
|
||||
$cur=0;
|
||||
} else {
|
||||
if ($cur == -1){
|
||||
return true; // unlimited mem!
|
||||
}
|
||||
$cur = get_real_size($cur);
|
||||
}
|
||||
|
||||
$new = get_real_size($newlimit);
|
||||
if ($new > $cur) {
|
||||
ini_set('memory_limit', $newlimit);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// ENCRYPTION ////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
|
|
|
@ -177,9 +177,11 @@ global $HTTPSPAGEREQUIRED;
|
|||
$CFG->admin = 'admin'; // This is relative to the wwwroot and dirroot
|
||||
}
|
||||
|
||||
/// Increase memory limits if possible
|
||||
raise_memory_limit('64M'); // We should never NEED this much but just in case...
|
||||
|
||||
/// Load up standard libraries
|
||||
|
||||
|
||||
require_once($CFG->libdir .'/textlib.class.php'); // Functions to handle multibyte strings
|
||||
require_once($CFG->libdir .'/weblib.php'); // Functions for producing HTML
|
||||
require_once($CFG->libdir .'/dmllib.php'); // Functions to handle DB data (DML)
|
||||
|
@ -188,11 +190,6 @@ global $HTTPSPAGEREQUIRED;
|
|||
require_once($CFG->libdir .'/deprecatedlib.php'); // Deprecated functions included for backward compatibility
|
||||
require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions
|
||||
|
||||
|
||||
/// Increase memory limits if possible
|
||||
|
||||
raise_memory_limit('64M'); // We should never NEED this much but just in case...
|
||||
|
||||
/// Disable errors for now - needed for installation when debug enabled in config.php
|
||||
if (isset($CFG->debug)) {
|
||||
$originalconfigdebug = $CFG->debug;
|
||||
|
|
|
@ -31,6 +31,71 @@ function init_performance_info() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to raise the memory limit to a new value.
|
||||
* Will respect the memory limit if it is higher, thus allowing
|
||||
* settings in php.ini, apache conf or command line switches
|
||||
* to override it
|
||||
*
|
||||
* The memory limit should be expressed with a string (eg:'64M')
|
||||
*
|
||||
* @param string $newlimit the new memory limit
|
||||
* @return bool
|
||||
*/
|
||||
function raise_memory_limit ($newlimit) {
|
||||
|
||||
if (empty($newlimit)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cur = @ini_get('memory_limit');
|
||||
if (empty($cur)) {
|
||||
// if php is compiled without --enable-memory-limits
|
||||
// apparently memory_limit is set to ''
|
||||
$cur=0;
|
||||
} else {
|
||||
if ($cur == -1){
|
||||
return true; // unlimited mem!
|
||||
}
|
||||
$cur = get_real_size($cur);
|
||||
}
|
||||
|
||||
$new = get_real_size($newlimit);
|
||||
if ($new > $cur) {
|
||||
ini_set('memory_limit', $newlimit);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts numbers like 10M into bytes.
|
||||
*
|
||||
* @param mixed $size The size to be converted
|
||||
* @return mixed
|
||||
*/
|
||||
function get_real_size($size=0) {
|
||||
if (!$size) {
|
||||
return 0;
|
||||
}
|
||||
$scan['MB'] = 1048576;
|
||||
$scan['Mb'] = 1048576;
|
||||
$scan['M'] = 1048576;
|
||||
$scan['m'] = 1048576;
|
||||
$scan['KB'] = 1024;
|
||||
$scan['Kb'] = 1024;
|
||||
$scan['K'] = 1024;
|
||||
$scan['k'] = 1024;
|
||||
|
||||
while (list($key) = each($scan)) {
|
||||
if ((strlen($size)>strlen($key))&&(substr($size, strlen($size) - strlen($key))==$key)) {
|
||||
$size = substr($size, 0, strlen($size) - strlen($key)) * $scan[$key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a directory.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue