Still necessary to use 'Status: 404 Not Found' for FCGI?

淺唱寂寞╮ 提交于 2019-12-30 09:43:39

问题


Usually, when sending a http status header from PHP, one would send the HTTP header like this:

header("HTTP/1.0 404 Not Found");

However, the PHP manual says that for FCGI hosts, one would need to send a "Status" header that is then converted into a HTTP header by the FCGI module:

header("Status: 404 Not Found");

I am running apache 2.2 with PHP using mod_fcgi on a Windows 7 machine and sending the header using just header("HTTP/1.0 404 Not Found"); seems to work fine.

Is this something that has changed recently? Do I still need to send a Status header for FCGI hosts? Could anyone also confirm this for other platforms (solaris, linux) and other webservers (nginx, lighttp)?


回答1:


I don't believe you need to use the 'Status' style header unless you have the option cgi.rfc2616_headers enabled.

The description of that option is http://php.net/manual/en/ini.core.php

"Tells PHP what type of headers to use when sending HTTP response code. If it's set 0, PHP sends a Status: header that is supported by Apache and other web servers. When this option is set to 1, PHP will send » RFC 2616 compliant headers. Leave it set to 0 unless you know what you're doing."

Basically you're sending HTTP style headers to PHP and then PHP converts these to the 'Status' style headers where necessary. It seems there were various bugs over the years where either these were either converted incorrectly or multiple 'Status' headers were sent at once - however all those bugs seem to be fixed now. So I think you're safe just setting the HTTP style headers and letting PHP convert them.

Also I just tested and sending the header("HTTP/1.0 404 Not Found"); works fine on my dev environment using FastCGI



来源:https://stackoverflow.com/questions/8828275/still-necessary-to-use-status-404-not-found-for-fcgi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!