Re: memory allocation error
| From: | Carol Peck | Date: | Mon, 12 Nov 2012 23:23:36 +0000 |
| Subject: | Re: memory allocation error | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-319700@lists.php.net to get a copy of this message | ||
On 11/12/2012 11:51 AM, Matijn Woudt wrote:
On Mon, Nov 12, 2012 at 3:17 PM, Carol Peck <carolapeck@gmail.com <mailto:carolapeck@gmail.com>> wrote:It's main purpose is to format the message before logging. I do know that things are getting logged properly. Thanks again. <?php /** * Error Handler class * * Handles E_USER_ERROR, E_USER_WARNING, E_WARNING, E_USER_NOTICE, * and E_NOTICE errors. */ class ErrorHandler { /** protected $_noticeLog = '/tmp/notice.log'; protected $_errorLog = '/tmp/error_handler.log'; public function __construct($message, $filename, $linenum, $vars) {Sebastian, Yes, I do , but this particular error never gets into my custom handler. I have also set it so that fatal errors fall through, and that doesn't seem to make any difference (again, probably because it never gets there).CarolCan you post the code of the error handler? I guess the bug is there. Bugs like these are mostly because of recursion errors or something. (Don't know if it's possible, but an error inside the error handler?) Fatal errors will btw always fall through, you can't catch fatal errors. You should, for testing, turn off your custom error handler and see what it does. - Matijn Ps. Please bottom-post on this mailing list. Here is the error class (I hope I"m posting the code the right way). I will turn this off for a while.
$this->message = $message;
$this->filename = $filename;
$this->line = $linenum;
$this->vars = $vars;
}
public static function handle($errno, $errmsg, $filename, $line, $vars)
{
$self = new self($errmsg, $filename, $line, $vars);
switch ($errno) {
case E_USER_ERROR:
return $self->handleError();
case E_USER_WARNING:
case E_WARNING:
return $self->handleWarning();
case E_USER_NOTICE:
case E_NOTICE:
return $self->handleNotice();
default:
// Returning false tells PHP to revert control to the
// default error handler
return false;
}
}
public function handleError()
{
// Get backtrace
ob_start();
debug_print_backtrace();
$backtrace = ob_get_flush();
$body =<<<EOT
A fatal error occured in the application:
Message: {$this->message}
File: {$this->filename}
Line: {$this->line}
Backtrace:
{$backtrace}
EOT;
// Use PHP's error_log() function to send an email
//error_log($body, 1, 'sysadmin@example.com', "Fatal error occurred\n");
error_log($body, 1, 'cpeck@wyom.net', "Subject: Fatal error occurred\n");
return error_log($body, 3, APP_PATH . $this->_errorLog);
exit(1); // non 0 exit status indicates script failure
}
/**
* Handle warnings
*
* Warnings indicate environmental errors; email sysadmin and
* continue
*
* @return boolean
*/
public function handleWarning()
{
$body =<<<EOT
An environmental error occured in the application, and may indicate a
potential larger issue:
Message: {$this->message}
File: {$this->filename}
Line: {$this->line}
EOT;
$body = date('[Y-m-d H:i:s] ') . $body . "\n";
return error_log($body,3, APP_PATH . $this->_errorLog);} /** * Handle notices * * @return boolean */
public function handleNotice()
{
$body =<<<EOT
A NOTICE was raised with the following information:
Message: {$this->message}
File: {$this->filename}
Line: {$this->line}
EOT;
$body = date('[Y-m-d H:i:s] ') . $body . "\n";
return error_log($body, 3, APP_PATH . $this->_noticeLog);
}
}
/**
* Set ErrorHandler::handle() as default error handler
*/
set_error_handler(array('ErrorHandler', 'handle'));