translate_memstring($curLimit)) { ini_set('memory_limit', $memoryLimit); } } /** * Turn a memory string, such as 512M into an actual number of bytes. * @param A memory limit string, such as "64M" */ function translate_memstring($memString) { switch(strtolower(substr($memString, -1))) { case "k": return round(substr($memString, 0, -1)*1024); case "m": return round(substr($memString, 0, -1)*1024*1024); case "g": return round(substr($memString, 0, -1)*1024*1024*1024); default: return round($memString); } } /** * Increase the time limit of this script. By default, the time will be unlimited. * @param $timeLimit The time limit in seconds. If omitted, no time limit will be set. */ function increase_time_limit_to($timeLimit = null) { if(!ini_get('safe_mode')) { if(!$timeLimit) { set_time_limit(0); } else { $currTimeLimit = ini_get('max_execution_time'); if($currTimeLimit && $currTimeLimit < $timeLimit) { set_time_limit($timeLimit); } } } }