捕获PHP致命错误 [英] Catch PHP Fatal Error

查看:84
本文介绍了捕获PHP致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个启用了Restful的Web服务站点,因此其他网站/ajax脚本可以调用该站点以获取/设置数据.但是,无论何时Web服务站点以某种方式返回PHP致命错误,返回的HTTP状态都是200,而不是500.是否有一种解决方法,以便每当发生致命错误时,返回500而不是200?或者,如果不可能,如何更改客户端以识别Web服务返回的致命错误?

I have a web service site that is restful enabled, so other websites/ajax script can make a call to the site to get/set data. However, whenever the web service site somehow returns a PHP fatal error, the HTTP status that is returned is 200 instead of 500. Is there a way to fix it so that whenever a fatal error occurs, returns 500 instead of 200? Or, if it is not possible, how can I change my client to recognize the fatal error returned by the webservice?

推荐答案

一种可能的方法是将默认响应设置为500,如果一切执行成功,则将响应设置为200:

One possible way would be to set the default response to 500, if everything executes successfully set the response to 200:

http_response_code(500);
render_my_page();
http_response_code(200);

这篇关于捕获PHP致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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