Chris@0: = Bytes::toInt($required))); Chris@0: } Chris@0: Chris@18: /** Chris@18: * Attempts to set the PHP maximum execution time. Chris@18: * Chris@18: * This function is a wrapper around the PHP function set_time_limit(). When Chris@18: * called, set_time_limit() restarts the timeout counter from zero. In other Chris@18: * words, if the timeout is the default 30 seconds, and 25 seconds into script Chris@18: * execution a call such as set_time_limit(20) is made, the script will run Chris@18: * for a total of 45 seconds before timing out. Chris@18: * Chris@18: * If the current time limit is not unlimited it is possible to decrease the Chris@18: * total time limit if the sum of the new time limit and the current time Chris@18: * spent running the script is inferior to the original time limit. It is Chris@18: * inherent to the way set_time_limit() works, it should rather be called with Chris@18: * an appropriate value every time you need to allocate a certain amount of Chris@18: * time to execute a task than only once at the beginning of the script. Chris@18: * Chris@18: * Before calling set_time_limit(), we check if this function is available Chris@18: * because it could be disabled by the server administrator. Chris@18: * Chris@18: * @param int $time_limit Chris@18: * An integer time limit in seconds, or 0 for unlimited execution time. Chris@18: * Chris@18: * @return bool Chris@18: * Whether set_time_limit() was successful or not. Chris@18: */ Chris@18: public static function setTimeLimit($time_limit) { Chris@18: if (function_exists('set_time_limit')) { Chris@18: $current = ini_get('max_execution_time'); Chris@18: // Do not set time limit if it is currently unlimited. Chris@18: if ($current != 0) { Chris@18: return set_time_limit($time_limit); Chris@18: } Chris@18: } Chris@18: return FALSE; Chris@18: } Chris@18: Chris@18: /** Chris@18: * Determines the maximum file upload size by querying the PHP settings. Chris@18: * Chris@18: * @return int Chris@18: * A file size limit in bytes based on the PHP upload_max_filesize and Chris@18: * post_max_size settings. Chris@18: */ Chris@18: public static function getUploadMaxSize() { Chris@18: static $max_size = -1; Chris@18: Chris@18: if ($max_size < 0) { Chris@18: // Start with post_max_size. Chris@18: $max_size = Bytes::toInt(ini_get('post_max_size')); Chris@18: Chris@18: // If upload_max_size is less, then reduce. Except if upload_max_size is Chris@18: // zero, which indicates no limit. Chris@18: $upload_max = Bytes::toInt(ini_get('upload_max_filesize')); Chris@18: if ($upload_max > 0 && $upload_max < $max_size) { Chris@18: $max_size = $upload_max; Chris@18: } Chris@18: } Chris@18: return $max_size; Chris@18: } Chris@18: Chris@0: }