Skip to content
Permalink
Browse files

Increase memory during shutdown for Fatal Error handling

  • Loading branch information...
adam1010
adam1010 committed Aug 13, 2015
1 parent 979820b commit 20c22444baf8d627215b66e767aa0180e545931c
Showing with 39 additions and 0 deletions.
  1. +2 −0 app/Config/core.php
  2. +37 −0 lib/Cake/Core/App.php
@@ -68,6 +68,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')`
@@ -888,6 +888,35 @@ protected static function _packageFormat() {
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 @@ protected static function _packageFormat() {
* @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_');
}

0 comments on commit 20c2244

Please sign in to comment.
You can’t perform that action at this time.