From e7e9723f8afb2818aec9faac413bb9ee24e3f5f5 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Tue, 18 Jun 2013 16:40:01 -0400 Subject: [PATCH] Added Application::$reservedMemorySize. --- framework/yii/base/Application.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/framework/yii/base/Application.php b/framework/yii/base/Application.php index 4d431b3..845c564 100644 --- a/framework/yii/base/Application.php +++ b/framework/yii/base/Application.php @@ -54,6 +54,13 @@ abstract class Application extends Module * If this is false, layout will be disabled. */ public $layout = 'main'; + /** + * @var integer the size of the reserved memory. A portion of memory is pre-allocated so that + * when an out-of-memory issue occurs, the error handler is able to handle the error with + * the help of this reserved memory. If you set this value to be 0, no memory will be reserved. + * Defaults to 256KB. + */ + public $reservedMemorySize = 262144; /** * @var string Used to reserve memory for fatal error handler. @@ -125,9 +132,9 @@ abstract class Application extends Module ini_set('display_errors', 0); set_exception_handler(array($this, 'handleException')); set_error_handler(array($this, 'handleError'), error_reporting()); - // Allocating twice more than required to display memory exhausted error - // in case of trying to allocate last 1 byte while all memory is taken. 1024 * 256 bytes - $this->_memoryReserve = str_repeat('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 1024); + if ($this->reservedMemorySize > 0) { + $this->_memoryReserve = str_repeat('x', $this->reservedMemorySize); + } register_shutdown_function(array($this, 'handleFatalError')); } }