//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
//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) {
//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) {
//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";
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 ////////////////////////////////////////////////
/// 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