mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-22 23:07:20 +00:00
Increase memory during shutdown for Fatal Error handling
This commit is contained in:
parent
979820b884
commit
20c22444ba
2 changed files with 39 additions and 0 deletions
|
@ -68,6 +68,8 @@
|
||||||
* - `renderer` - string - The class responsible for rendering uncaught exceptions. If you choose a custom class you
|
* - `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.
|
* 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?
|
* - `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
|
* - `skipLog` - array - list of exceptions to skip for logging. Exceptions that
|
||||||
* extend one of the listed exceptions will also be skipped for logging.
|
* extend one of the listed exceptions will also be skipped for logging.
|
||||||
* Example: `'skipLog' => array('NotFoundException', 'UnauthorizedException')`
|
* Example: `'skipLog' => array('NotFoundException', 'UnauthorizedException')`
|
||||||
|
|
|
@ -888,6 +888,35 @@ class App {
|
||||||
return static::$_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.
|
* Object destructor.
|
||||||
*
|
*
|
||||||
|
@ -897,6 +926,14 @@ class App {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function shutdown() {
|
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) {
|
if (static::$_cacheChange) {
|
||||||
Cache::write('file_map', array_filter(static::$_map), '_cake_core_');
|
Cache::write('file_map', array_filter(static::$_map), '_cake_core_');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue