diff --git a/app/Config/core.php b/app/Config/core.php index a55347ce3..093087a70 100644 --- a/app/Config/core.php +++ b/app/Config/core.php @@ -71,6 +71,8 @@ * - `renderer` - string - The class responsible for rendering uncaught exceptions. If you choose a custom class you * should place the file for that class in app/Lib/Error. This class needs to implement a render method. * - `log` - boolean - Should Exceptions be logged? + * - `extraFatalErrorMemory` - integer - Increases memory limit at shutdown so fatal errors are logged. Specify + * amount in megabytes or use 0 to disable (default: 4 MB) * - `skipLog` - array - list of exceptions to skip for logging. Exceptions that * extend one of the listed exceptions will also be skipped for logging. * Example: `'skipLog' => array('NotFoundException', 'UnauthorizedException')` diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index fa64f64f4..45ef3ff5c 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -888,6 +888,35 @@ class App { return static::$_packageFormat; } +/** + * Increases the PHP "memory_limit" ini setting by the specified amount + * in kilobytes + * + * @param string $additionalKb Number in kilobytes + * @return void + */ + public static function increaseMemoryLimit($additionalKb) { + $limit = ini_get("memory_limit"); + if (!is_string($limit) || !strlen($limit)) { + return; + } + $limit = trim($limit); + $units = strtoupper(substr($limit, -1)); + $current = substr($limit, 0, strlen($limit) - 1); + if ($units === "M") { + $current = $current * 1024; + $units = "K"; + } + if ($units === "G") { + $current = $current * 1024 * 1024; + $units = "K"; + } + + if ($units === "K") { + ini_set("memory_limit", ceil($current + $additionalKb) . "K"); + } + } + /** * Object destructor. * @@ -897,6 +926,14 @@ class App { * @return void */ public static function shutdown() { + $megabytes = Configure::read('Error.extraFatalErrorMemory'); + if ($megabytes === null) { + $megabytes = 4; + } + if ($megabytes !== false && $megabytes > 0) { + static::increaseMemoryLimit($megabytes * 1024); + } + if (static::$_cacheChange) { Cache::write('file_map', array_filter(static::$_map), '_cake_core_'); }