问题描述
我运行的Apache 2.2.15和PHP 5.3.2,display_errors设置禁用,display_startup_errors禁用log_errors启用。
I am running Apache 2.2.15 with PHP 5.3.2, 'display_errors' disabled, 'display_startup_errors' disabled, 'log_errors' enabled.
在我的设置(所以我认为这是一个规范),PHP中止致命的错误,这是很好的,而设置HTTP状态code至500 的。致命错误包括E_ERROR,E_PARSE,E_CORE_ERROR,E_COMPILE_ERROR,E_USER_ERROR和可能,E_RECOVERABLE_ERROR(不能触发它自己,所以不能轻易查个究竟)。我认为这是一个好主意,它并设置code至500,因为我觉得这是应该做的正确的事情 - 很明显,如果你的脚本包含语法错误和/或不能做什么是应该在运行时做,它是一个服务器错误,如果我们考虑服务器的PHP的一部分。
At my setup (so I consider it a norm), PHP aborts on fatal errors, which is good, and sets HTTP status code to 500. Fatal errors include E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR and, probably, E_RECOVERABLE_ERROR (cannot trigger it myself, so can't easily check what happens). I think it is a good idea that it does set the code to 500, because I think it is the right thing to do - obviously if your script contains syntax errors and/or fails to do what is supposed to do at runtime, it is a server error, if we consider PHP part of the server.
现在,这里是重要的部分:
反正我现在已经安装了XDebug跟踪误差更好,但我可以看到,现在,无论错误,即使该脚本之前中止的致命错误的 HTTP状态code是永远200 的。这打破了我的客户端通过HTTP'谈判'到Apache / PHP:|
Anyway, I have now installed XDebug to track errors better, but I can see that now, no matter the error, even though the script aborts as before on fatal errors, the HTTP status code is always 200. This breaks my client that 'talks' to Apache/PHP via HTTP :|
此外,display_errors设置为开/ 1,使得PHP不再设置HTTP状态code至500和展品完全一样的行为与上述XDebug的。
Also, setting display_errors to On/1, makes PHP no longer set HTTP status code to 500 and exhibits exactly the same behavior as with XDebug above.
我非常依赖于可靠的状态code行为在这里,而这一切使我相信这是某种侥幸或随机样的天气..还是我失去了一些东西?
I am very much dependent on reliable status code behavior here, and this all leads me to believe it's some kind of fluke or random like weather.. or am I missing something?
更新
有是oulines这一问题的博客文章:
There is a blog post which oulines the issue:http://talideon.com/weblog/2008/02/php-errors.cfm
就我而言,我有残疾的XDebug,看到它是什么原因导致摆在首位的不良行为。我只用它的堆栈跟踪无论如何,现在使用自定义的错误处理程序,与其。此外,链接的文章是从2008年,显然是PHP的确实设置HTTP状态code至500自动这些天。它这样做是在这里。如果没有了XDebug,当然了。
For my part, I have disabled XDebug, seeing as it is what causes the bad behavior in the first place. I only used it for stack tracing anyway, and now use a custom error handler for that instead. Also, the linked article is from 2008, apparently PHP does set HTTP status code to 500 automatically these days. It does so here. Without XDebug, of course.
推荐答案
我假设你正在使用自定义错误处理程序发出了500。
I assume you are using a custom error handler to emit the 500.
我不知道的XDebug那么好,但根据,它注册了自己的错误处理程序,在此过程中可能重写你的:
I don't know XDebug that well, but according to this article, it registers its own error handler, probably overriding yours in the process:
请注意,Xdebug的的扩展错误显示不工作,如果你使用register_error_handler()定义自定义错误处理程序。这是因为,Xdebug的内部使用相同的机制。如果您的脚本中使用自定义错误处理,你仍然可以使用函数xdebug_get_function_stack()输出的堆栈跟踪您的自定义错误处理程序。
不过,对于生产使用,你不会反正激活了XDebug,是吗?
However, for production use, you are not going to activate XDebug anyway, are you?
至于为什么一个200的输出,当您激活的display_errors()
,我不明白。您可以发布您的自定义错误处理函数来看待?
As for why a 200 is output when you activate display_errors()
, that I don't understand. Can you post your custom error handler function to look at?
这篇关于如何使PHP的HTTP状态code至500中的任何错误情况时自动? (包括那些不能由用户来处理)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!