将所有 PHP 错误输出到数据库而不是 error_log [英] Outputting all PHP errors to database not error_log
本文介绍了将所有 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.
>
手册中的修改示例:>
Modified example from the manual:
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屋!
查看全文