Jump to content

404 headers broken (FastCGI?)


southglos

Recommended Posts

Hi

 

Hoping someone can shed some light on why my 404 code has gone haywire lately...

 

Basic scenario - I have a PHP page that looks up some information and returns an HTML page.  If what it's asked for doesn't exist, I return a 404 status code and suitably apologetic HTML.

 

I used to do this with header("HTTP/1.0 404 Not Found"); and all was well with the world.

 

Then my hosting provider upgraded PHP on the servers (changing to using PHP via FastCGI in the process, I think), and my error pages started coming back completely blank (not even a header returned) or badly mangled (usually just the latter half of my HTML then 200 OK and a bunch of headers).

 

Changed over to using header('',true,404); and all became well again.

 

Looks like something has changed again, and now my 404 pages are coming back as 200s.  Or, if I change how I do things, blank pages again.  Oddly, it seems to be only 404s that have the problem - I can send 410s or 500s or whatever quite happily, so it's definitely something odd under the bonnet.

 

Here's a summary of what I've tried and the effects.  In all cases assume a <?php before and a echo('hello'); ?> afterwards:

 

header('HTTP/1.0 404 Not Found');  -- no output

header('HTTP/1.0 410 Gone'); -- works as expected, 410 Gone

header('HTTP/1.0 404 Blah', true, 404); -- no output

header('HTTP/1.0 410 Blah', true, 410); -- works as expected, 410 Blah

header('', true, 404); -- 200 OK

header('', true, 410); -- 200 OK

header(' ', true, 404); -- no output

header(' ', true, 410); -- 410 Gone

header('Status: 404 Not Found'); -- no output

header('Status: 410 Gone'); -- 410 Gone

 

So, as you can see, I can't output pages with a status of 404 at the moment.  Oh, and when I say no output, I really mean no output - no status header, nor any other sort of header, let alone the hello content.

 

I suspect it's something to do with how PHP is set up on the server now - ever since they changed to FastCGI it's been horribly sluggish to start executing PHP, too.  I think getting every wrinkle ironed out and the performance tuned hasn't been a priority.

 

PHP version is 5.2.6, php_sapi_name() returns "cgi-fcgi", Apache 1.3.41, running on some flavour of Linux (Red Hat, I think).

 

I've tried my hoster's support line on this before, and got the response "we do not provide scripting help".  So, if it is a problem with how they've got PHP set up at the moment, I need to be able to spell out exactly what the problem is and what they need to do about it to have any hope of not getting the immediate brush-off again.  I'm hoping it's something stupid I'm missing, as I've got more chance of fixing that :-)

 

Cheers.

 

Link to comment
https://forums.phpfreaks.com/topic/118964-404-headers-broken-fastcgi/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.