Apache resets connection when PHP tells it to 404

1.2k views Asked by At

Given the following PHP 5.1.6 code being served through Apache 2.2.9:

<?php
header("HTTP/1.1 404 Not Found");

When I browse to this file (with any browser) I get a "connection reset" message. (Firefox says "The connection to the server was reset while the page was loading.", and Chrome says "The connection to staging.neopets.com was interrupted." It makes no difference whether there's any body after the header call.

httpd.conf has rewrite rules that force all requests to run through a front controller script. This is how it's worked for years. The front controller tries to route the request, and if it can't, it sets the response code to 404, shows some error copy, and exits. For whatever reason, today it decided to lose its mind and blow up whenever a

error.log shows nothing. access.log shows the requests being served as 404s:

192.168.0.2 - - [26/Jan/2012:12:03:11 -0800] "GET /text.php HTTP/1.1" 404 20 "-" "Mozilla/5.0 (X11; Linux i686; rv:8.0.1) Gecko/20100101 Firefox/8.0.1"

The Apache config has not been touched in months. All other header responses work properly (401, 403, 200, 302, etc.), everything else is totally normal, but for some reason if I have PHP make the call above, it resets the connection.

I even watched it with Wireshark and it sends back a whole bunch of RST,ACK packets after the request is sent.

Doing wget localhost/test.php (from the machine in question) works fine, but doing wget badhost/test.php (from another machine) shows a connection reset error as well. Maybe Apache is doing some kind of reverse IP lookup on remote requests for 404s and melting down?

EDIT: After further investigation, turns out it's some network problem where 404s between the hosting facility and our office are killed with a connection reset. So, closing because it's not something that anyone here can answer ;-) Thanks!

1

There are 1 answers

1
Radu Murzea On

That header that you send from your PHP script is not what makes Apache display its 404 page. Apache displays a 404 page (and sends a 404 Header) when it can't find the requested file. Since this is not the case here (because test.php is found and executed), that 404 header has no sense. That is probably what got your browser(s) confused.

If you call this as part of some application error handling or something, what you should do instead is redirect the user to the application's custom "File not found" page.