Permalink
Browse files

moodle--eduforge--1.3.3--patch-335 Now memory_limit can be overriden …

…by higher config settings from php.ini, commandline, httpd.conf, .htaccess
  • Loading branch information...
1 parent ff75e0f commit 726f4ca31752f190d5af3cccd51e4274c7e7285e martinlanghoff committed Nov 18, 2004
Showing with 57 additions and 5 deletions.
  1. +1 −1 admin/cron.php
  2. +1 −1 backup/backup.php
  3. +1 −1 backup/restore.php
  4. +1 −1 backup/try.php
  5. +52 −0 lib/moodlelib.php
  6. +1 −1 lib/setup.php
View
@@ -144,7 +144,7 @@
//Execute backup's cron
//Perhaps a long time and memory could help in large sites
@set_time_limit(0);
- @ini_set("memory_limit","128M");
+ raise_memory_limit("128M");
if (file_exists("$CFG->dirroot/backup/backup_scheduled.php") and
file_exists("$CFG->dirroot/backup/backuplib.php") and
file_exists("$CFG->dirroot/backup/lib.php") and
View
@@ -88,7 +88,7 @@
//Adjust some php variables to the execution of this script
@ini_set("max_execution_time","3000");
- @ini_set("memory_limit","128M");
+ raise_memory_limit("128M");
//Call the form, depending the step we are
if (!$launch) {
View
@@ -95,7 +95,7 @@
//Adjust some php variables to the execution of this script
@ini_set("max_execution_time","3000");
- @ini_set("memory_limit","128M");
+ raise_memory_limit("memory_limit","128M");
//Call the form, depending the step we are
if (!$launch) {
View
@@ -21,7 +21,7 @@
//Adjust some php variables to the execution of this script
@ini_set("max_execution_time","3000");
- @ini_set("memory_limit","128M");
+ raise_memory_limit("128M");
echo "<pre>\n";
View
@@ -3322,6 +3322,58 @@ function unzip_cleanfilename ($p_event, &$p_header) {
return 1;
}
+/**
+* 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')
+*
+* Return boolean
+*
+* @param value string with the new memory limit
+*/
+function raise_memory_limit ($newlimit) {
+
+ if (empty($newlimit)) {
+ return false;
+ }
+
+ $cur = return_bytes(@ini_get('memory_limit'));
+ $new = return_bytes($newlimit);
+
+ if ($new > $cur) {
+ ini_set('memory_limit', $newlimit);
+ return true;
+ }
+ return false;
+}
+
+/**
+* Function to transform strings like 5M or 128k into bytes.
+* Taken from PHP's documentation (see entry for ini_get())
+*
+* Return integer (in bytes)
+*
+* @param value string with the value
+*/
+function return_bytes($val) {
+ $val = trim($val);
+ $last = $val{strlen($val)-1};
+ switch($last) {
+ case 'k':
+ case 'K':
+ return (int) $val * 1024;
+ break;
+ case 'm':
+ case 'M':
+ return (int) $val * 1048576;
+ break;
+ default:
+ return $val;
+ }
+}
function unzip_show_status ($list,$removepath) {
//This function shows the results of the unzip execution
View
@@ -71,7 +71,7 @@
/// Increase memory limits if possible
- @ini_set('memory_limit' , '64M'); // We should never NEED this much but just in case...
+ raise_memory_limit('64M'); // We should never NEED this much but just in case...
/// Load up any configuration from the config table

0 comments on commit 726f4ca

Please sign in to comment.