Re: memory allocation error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 11/12/2012 11:51 AM, Matijn Woudt wrote:

On Mon, Nov 12, 2012 at 3:17 PM, Carol Peck <carolapeck@xxxxxxxxx <mailto:carolapeck@xxxxxxxxx>> wrote:

    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).

    Carol


Can 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. 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)
  {
    $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@xxxxxxxxxxx', "Fatal error occurred\n"); error_log($body, 1, 'cpeck@xxxxxxxx', "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'));

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux