捕获生产环境中的所有应用程序异常和PHP错误
How can I catch all application exceptions and PHP errors in production environment?
I am using a custom MVC framework, and I have a entry point where my MVC framework starts. So I already wrap this entry point with a general:
try{
//start point of mvc framework that load main class
//that manage request, response, route etc
}catch(Exception $e) {
//return response 404 to client if something goes wrong
}
Is this enough? What about PHP errors?
It's a production environment so I don't the users to see the errors, but I want to log all for debugging. Is there an opensource PHP class that log errors in a elegant way that I can inspire from?
如何在生产环境中捕获所有应用程序异常和PHP错误? p>
我正在使用自定义MVC框架,我有一个入口点,我的MVC框架启动。 所以我已经用一个通用程序包装了这个入口点: p>
尝试{
//加载主类的mvc框架的起点
//管理请求,响应, catch等等
} catch(异常$ e){
//如果出现问题则将响应404返回给客户端
}
code> pre>
这样就够了吗? PHP错误怎么样? p>
这是一个生产环境,所以我没有用户看到错误,但我想记录所有错误。 是否有一个开源PHP类以优雅的方式记录错误,我可以从中激发这些错误? p>
div>
Nope, an exception handler is not enough. You should also transform php notices/errors/warnings into exceptions so that you can catch them as well, I have an example here: http://codehackit.blogspot.com/2012/01/php-errorswarningsnotices-to-exceptions.html Unfortunately most of PHPs built in functions still don't throw exceptions but these couple lines fix that ;)