Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Component/Utility/Environment.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
35 // - The memory limit is greater than or equal to the memory required for | 35 // - The memory limit is greater than or equal to the memory required for |
36 // the operation. | 36 // the operation. |
37 return ((!$memory_limit) || ($memory_limit == -1) || (Bytes::toInt($memory_limit) >= Bytes::toInt($required))); | 37 return ((!$memory_limit) || ($memory_limit == -1) || (Bytes::toInt($memory_limit) >= Bytes::toInt($required))); |
38 } | 38 } |
39 | 39 |
40 /** | |
41 * Attempts to set the PHP maximum execution time. | |
42 * | |
43 * This function is a wrapper around the PHP function set_time_limit(). When | |
44 * called, set_time_limit() restarts the timeout counter from zero. In other | |
45 * words, if the timeout is the default 30 seconds, and 25 seconds into script | |
46 * execution a call such as set_time_limit(20) is made, the script will run | |
47 * for a total of 45 seconds before timing out. | |
48 * | |
49 * If the current time limit is not unlimited it is possible to decrease the | |
50 * total time limit if the sum of the new time limit and the current time | |
51 * spent running the script is inferior to the original time limit. It is | |
52 * inherent to the way set_time_limit() works, it should rather be called with | |
53 * an appropriate value every time you need to allocate a certain amount of | |
54 * time to execute a task than only once at the beginning of the script. | |
55 * | |
56 * Before calling set_time_limit(), we check if this function is available | |
57 * because it could be disabled by the server administrator. | |
58 * | |
59 * @param int $time_limit | |
60 * An integer time limit in seconds, or 0 for unlimited execution time. | |
61 * | |
62 * @return bool | |
63 * Whether set_time_limit() was successful or not. | |
64 */ | |
65 public static function setTimeLimit($time_limit) { | |
66 if (function_exists('set_time_limit')) { | |
67 $current = ini_get('max_execution_time'); | |
68 // Do not set time limit if it is currently unlimited. | |
69 if ($current != 0) { | |
70 return set_time_limit($time_limit); | |
71 } | |
72 } | |
73 return FALSE; | |
74 } | |
75 | |
76 /** | |
77 * Determines the maximum file upload size by querying the PHP settings. | |
78 * | |
79 * @return int | |
80 * A file size limit in bytes based on the PHP upload_max_filesize and | |
81 * post_max_size settings. | |
82 */ | |
83 public static function getUploadMaxSize() { | |
84 static $max_size = -1; | |
85 | |
86 if ($max_size < 0) { | |
87 // Start with post_max_size. | |
88 $max_size = Bytes::toInt(ini_get('post_max_size')); | |
89 | |
90 // If upload_max_size is less, then reduce. Except if upload_max_size is | |
91 // zero, which indicates no limit. | |
92 $upload_max = Bytes::toInt(ini_get('upload_max_filesize')); | |
93 if ($upload_max > 0 && $upload_max < $max_size) { | |
94 $max_size = $upload_max; | |
95 } | |
96 } | |
97 return $max_size; | |
98 } | |
99 | |
40 } | 100 } |