]> git.mjollnir.org Git - moodle.git/commitdiff
Merged from MOODLE_14_STABLE moodle--eduforge--1.3.3--patch-335 Now memory_limit...
authormartinlanghoff <martinlanghoff>
Thu, 18 Nov 2004 02:55:06 +0000 (02:55 +0000)
committermartinlanghoff <martinlanghoff>
Thu, 18 Nov 2004 02:55:06 +0000 (02:55 +0000)
admin/cron.php
backup/backup.php
backup/restore.php
backup/try.php
lib/moodlelib.php
lib/setup.php

index 9972b2918fd9d7e48da00bb5bc743dbdd59fb5f6..574886e632d30f84f82084600dec1944c5e3a512 100644 (file)
         //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
index c81fcbed3e14975ca7d4c9aa0a32bbd1039f93f5..8ccdf1adbe00a115a67d2f276a6f917ce25a7367 100644 (file)
@@ -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) {
index 300fb7bcb6474e6f34d9ca50754477d1b8534ff3..0a2c0111001ea5d096d65adc8bdfcbb9aba61a3c 100644 (file)
@@ -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) {
index 60cd8254024e47143d01c4f490057c704661fdbd..34ad2ff407f0f01fb9029c936a391a38f284daab 100644 (file)
@@ -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";
 
index 4792523e26c687c717fae7452bf71fc21db86ad9..30d22943d7a6e1534ca2922f758071b5290b3215 100644 (file)
@@ -3230,6 +3230,58 @@ 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')
+* 
+* 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;
+   }
+}
 
 /// ENCRYPTION  ////////////////////////////////////////////////
 
index 0eb29ecb87fbbe85087f2967ec629fc0de5149c9..f5cd653f1a5aec98f93b81b383d0ec34340d46d4 100644 (file)
@@ -126,7 +126,7 @@ global $THEME;
 
 /// 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