mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-25 16:27:20 +00:00
Merge branch 'memory-fix' into 2.8.
This change automatically increases the memory limit when handling fatal errors. The intent is to bump the memory limit enough to allow logging of the fatal error source. Refs #7224
This commit is contained in:
commit
7bbdcb207b
2 changed files with 39 additions and 0 deletions
|
@ -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')`
|
||||
|
|
|
@ -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_');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue