如何让 PHP 在遇到错误时显示 Apache 的 500 错误页面,而不是空白页面?
我为 404、403 等以及 500 的自定义错误文档设置了 apache 指令。但是,PHP 在遇到致命错误时,会显示空白页面而不是触发 apache 500 响应。
我不需要显示错误详细信息或类似的内容,因为它们当前已正确记录在 apache error_logs 中,所以我认为它与 error_reporting 或 display_errors 没有任何关系,两者都设置正确。
这里有一些类似的问题,但还没有找到满足我需要的答案。基本上,在出现语法错误之类的情况下,我想查看 apache 500 错误页面,而不是空白页面。这不是 PHP 中可以捕获和处理的问题,因为语法错误是无法捕获的。
这似乎已在 php 5.2.4 中修补/修复,如下所示: http://www.mail-archive.com/[email protected]/msg28557.html
但是,我们使用的是 PHP 5.2.17,目前升级不可行。有没有人有任何解决方案/解决方法可能会在 apache 中针对任何 PHP 语法/致命错误触发 500 错误?
I have apache directives set up for custom error docs for 404, 403, etc, as well as 500. However, PHP, upon encountering a fatal error, displays a blank page instead of triggering the apache 500 response.
I don't need to display the error details or anything like that, as they are currently logged correctly in apache error_logs, so I don't think it has anything to do with error_reporting or display_errors, both of which are set correctly.
There are some similar questions here on SO, but haven't found an answer that does what I need. Basically, in the case of something like a syntax error, I want to see the apache 500 error page, NOT a blank page. This is not something that can be caught and handled in PHP, since syntax errors are uncatchable.
This appears to have been patched/fixed in php 5.2.4, as seen here: http://www.mail-archive.com/[email protected]/msg28557.html
However, we are using PHP 5.2.17, and an upgrade is not feasible at this time. Does anyone have any solutions / workarounds that might work to trigger 500 errors in apache for any PHP syntax/fatal error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这是否有效:注册一个 关闭处理程序 并显示适当的页面。
每当发生致命错误时,应该调用关闭处理程序。确保在脚本之上注册处理程序。
Not sure if this works: register a shutdown handler and display the appropriate page.
The shutdown handler should get called whenever a fatal error occurs. Make sure that you register the handler on top of your script.