[英]How do I handle parse and fatal errors?
I wrote a custom error handler for my site and I'm aware that PHP doesn't allow handling of parse and fatal errors. 我为我的站点编写了一个自定义错误处理程序,并且我知道PHP不允许处理解析错误和致命错误。 Is there something I can do to make it handle these errors?
我可以做些什么使它处理这些错误吗? I don't want them being outputted to the user (but I want to use my error handler for them).
我不希望将它们输出给用户(但我想对它们使用错误处理程序)。
Thanks! 谢谢!
You could try register_shutdown_function
. 您可以尝试
register_shutdown_function
。 If there is an error (even parse one) in one of files you have included/required this function will still be called. 如果您包含/需要的一个文件中存在错误(甚至解析为一个错误),该函数仍将被调用。
Though you won't be able to use debug_backtrace
because shutdown function will be called outside of your error, you could try to use error_get_last
to get some information about the error. 尽管由于将在错误之外调用关闭函数,所以您将无法使用
debug_backtrace
,但是您可以尝试使用error_get_last
获取有关该错误的一些信息。
If it can't parse your script, it won't be able to parse your custom error handler. 如果无法解析脚本,则无法解析自定义错误处理程序。
You should have display_errors
off in your php.ini
and also set error_reporting
to none when your site is in production. 您应该在
php.ini
关闭display_errors
,并在网站投入生产时将error_reporting
设置为none。
Also, I believe set_error_handler()
can handle fatal errors. 另外,我相信
set_error_handler()
可以处理致命错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.