Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)?

like image 616
F21 Avatar asked Oct 24 '22 12:10

F21


1 Answers

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

like image 179
Danack Avatar answered Oct 27 '22 06:10

Danack