代码之家  ›  专栏  ›  技术社区  ›  Todd Moses

PHP中全局错误处理的最佳实践?

  •  4
  • Todd Moses  · 技术社区  · 16 年前

    我使用了一个在php 5中将错误转换为异常的类,它将错误记录到一个文件中,并/或通过电子邮件将其发送到指定的帐户。有更好的方法吗?我知道这方面有些事情可以做得更好。我正在使用设置错误处理程序。

    set_error_handler("exception_error_handler");
    

    我的代码做了它应该做的,它记录和电子邮件错误,但我是做这个过程的最佳方式。如果数据连接出现错误,最好将其记录到数据库中。网站的行业标准是什么?

    2 回复  |  直到 16 年前
        1
  •  6
  •   symcbean    16 年前

        2
  •  3
  •   The Pixel Developer    16 年前

    Kohana

    /**
    * PHP error handler, converts all errors into ErrorExceptions. This handler
    * respects error_reporting settings.
    *
    * @throws ErrorException
    * @return TRUE
    */
    public static function error_handler($code, $error, $file = NULL, $line = NULL)
    {
        if (error_reporting() & $code)
        {
            // This error is not suppressed by current error reporting settings
            // Convert the error into an ErrorException
            throw new ErrorException($error, $code, 0, $file, $line);
        }
    
        // Do not execute the PHP error handler
        return TRUE;
    }