问题描述
我想知道如果我可以在一个包含的方法中挂钩,那么如果我的任何一个页面(使用这个包含的)崩溃了,那将会给我发送调试日志。
I am wondering if I can hook a method in a include, that will email me the debug logs if any of my pages (that uses that include) crashed.
是否有一个在致命错误后执行的方法?
Is there a method that is executed after a fatal error?
推荐答案
可以使用 register_shutdown_function()
为此。您将函数名称作为参数传递给此函数,并且在应用程序退出时调用该函数,无论什么原因。
You can use register_shutdown_function()
for this. You pass a function name as a parameter to this function, and that function is called when the application exits, for whatever reason.
您可以使用这段时间来捕获并记录任何致命错误,但是您不能从他们中恢复(他们是致命的,毕竟)。我认为在这个功能中遇到一个致命的错误,它的游戏结束了。没有日志记录。
You can use this time to catch and log any fatal errors, but you can't recover from them (they are fatal, after all). I think encounter a fatal error within this function, it's game over. There's no logging that.
在关机功能中,您需要检查关机是否是由于致命错误,并运行日志记录代码: p>
In your shutdown function, you'll want to check if the shutdown was due to a fatal error and run logging code if it was:
function shutdown() {
$lastError = error_get_last(); // returns an array with error information:
switch($lastError['type']){
case E_ERROR:
case E_PARSE:
case E_CORE_ERROR:
case E_CORE_WARNING:
case E_COMPILE_ERROR:
case E_COMPILE_WARNING:
// log the fatal error
break;
}
}
这篇关于我可以钩住一个方法到我的php文件,如果任何页面崩溃应该给我发邮件页面和错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!