Apache/PHP在错误页面上返回HTTP状态代码200 [英] Apache/PHP returns HTTP Status Code 200 on error pages

查看:338
本文介绍了Apache/PHP在错误页面上返回HTTP状态代码200的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在CentOS 7上运行PHP 5.4,当有一个php文件引发错误(异常或语法错误)时,它将返回HTTP 200状态代码,而不是500.

I'm running PHP 5.4 on CentOS 7 and when there is a php file that throws an error (either an exception, or a syntax error) it returns an HTTP 200 status code instead of 500.

当PHP遇到错误时,如何获取500服务器错误?

How can I get it to return a 500 server error when PHP encounters an error?

我尝试着查看其他Stackoverflow帖子,它们似乎都指向返回自己的500错误代码的解决方案(我认为这应该是PHP本身的正常行为,而无需我手动触发http标头,根据此信息: PHP因错误而发出500-其中)它也指出Xdebug是一个可能的问题,但是即使在没有Xdebug的情况下重建服务器,我的问题仍然存在.

I've tried looking at other Stackoverflow posts, and they all seem to point to solutions around returning your own 500 error code (which I believe should be the normal behavior of PHP on it's own without me needing to manually fire the http header, as per this info: PHP emitting 500 on errors - where is this documented?) It also points to Xdebug as being a possible issue, but my problem persists even when I rebuild the server without Xdebug.

我具有的相关设置是:

  • display_errors:开
  • display_startup_errors:开
  • error_reporting:-1(这将导致报告所有错误)

推荐答案

根据 a PHP错误报告,此处描述的行为是由于如何设置display_errors.

According to a PHP bug report, the behavior described here is due to how display_errors is set.

[2010-02-03 19:03 UTC] derick@php.net

[2010-02-03 19:03 UTC] derick@php.net

之所以需要关闭显示错误,是因为显示的错误会生成输出,并且输出会导致发送标头.恐怕我们对此无能为力.

The reason why display errors needs to be turned of, is because displayed errors generate output, and output causes the headers to be send out. I'm afraid we can't do much about this.

这个问题的答案是:

  • 打开display_errors时,它将始终返回200.
  • 关闭display_errors时,它将返回500.
  • When display_errors is on it will return 200 always.
  • When display_errors is off it will return 500.

这篇关于Apache/PHP在错误页面上返回HTTP状态代码200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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