Premature end of script headers: php5.cgi

I’m getting this error all over the place today. It’s been a stressful 24 hours. So I push out UserNameCheck.com last week, a simple little pet project. Few people I know say it’s a nice idea, blah dee blah. I email it over to Tina at swiss-miss who loves it and posts it straight to her site and 24hours later the site has been picked up by cnet, lifehacker, the twitterverse, delicious and thousands of other places. Yesterday the site went from 12 unique visitors to over 14,000 and it perfomed over 440,000 user names checks.

Now here is where the story turns nasty. See I was using cake as my php rapid prototyping tool of choice. Cake has these things called routers, they allow you to make url patterns and map them to controllers and controller methods, it’s very cool.

I had a router that looked like…

$Route->connect('/*', array('controller' => 'sites', 'action' => 'index'));

Usernamecheck.com only has 1 real page, so I just wanted to point any page at that page, it seemed innocent enough.

The issue is that any file would then try to return the index view. If for example I included files in my index that didn’t exists, the 404 would try to return the index, and since it was returning the index it would try and include those files, which would return the index….. repeat to silent and nasty web server death. The first time I’ve seen a missing favicon.ics destroy a server.

At about 9am this morning, just as the vast majority of the lifehacker traffic was coming across the server passed away.

Many many thanks to dreamhost, who finally responded to me with the issue (not the exact cause, but enough for me to figure it out). All I had to do was…

$Route->connect('/', array('controller' => 'sites', 'action' => 'index'));

So now erroneous pages that aren’t index will return the 404 rather than the index page. Problem fixed.

My load average was…

load average: 117.09, 77.65, 34.11

now it’s running at…

load average: 15.60, 11.10, 12.27

There is however no happy end to this tail.

I am now getting…

Premature end of script headers: php5.cgi, referer: http://usernamecheck.com/

This is super weird. _I_ haven’t changed anything, other than the router. Add to this the fact that if I make my index router like this…

$Route->connect('/runtest', array('controller' => 'sites', 'action' => 'index'));

Then go to username.com/runtest it seems to work. So it’s something to do with that root router. Throw in additional weirdness I’m seeing on hexday, mentioned.us and this blog and I’m starting to get very confused and in the need of a stiff drink.

I’ve googled, tried advice on cakebaker, and other locations. I would really rather not try to recompile php down to php4 or with php and the most recent zend (which was one suggestion), I’ve edited the awesomely named cake function __() which lives in basic.php. That didn’t change a thing.

I’m pretty much at a loss.


About this entry