将所有PHP错误输出到数据库而不是error_log [英] Outputting all PHP errors to database not error_log

查看:106
本文介绍了将所有PHP错误输出到数据库而不是error_log的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将所有PHP错误写入MySQL而不是标准的error_log文件。我猜这是可能的,如果我从头开始编写自己的错误处理程序,但我有很多遗留代码到位,理想情况下,我只会做出1个全球变化,就是这样。可以这样做吗?

Is it possible to make all PHP errors be written to MySQL instead of to the standard error_log file. I guess this would be possible if i wrote my own error handler from scratch but i have a lot of legacy code in place and ideally i would just make 1 global change and that would be it. Can this be done?

推荐答案

我不认为没有构建自己的错误处理程序可以做到,但从技术上讲,是您正在寻找的全球变化。

I don't think it can be done without building an own error handler, but technically, that is the one global change you're looking for.

手册

function myErrorHandler($errno, $errstr, $errfile, $errline)
{
     // you'd have to import or set up the connection here 
     mysql_query("INSERT INTO error_log (number, string, file, line) ".
                 "VALUES .....");         

    /* Don't execute PHP internal error handler */
    return true;
}

然后

// set to the user defined error handler
$old_error_handler = set_error_handler("myErrorHandler");

这篇关于将所有PHP错误输出到数据库而不是error_log的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆