Tuesday, February 10, 2009

Gotcha Of The Day: Apache and PHP Crashing On Vista

So, I'm minding my own business, hacking away at some PHP code on my Windows Laptop, when all of a sudden my web app starts reporting this gem of an error:

Network Timeout
The server at www.localhost.com is taking too long to respond.

What the heck? Then, I noticed that Apache crashed and Windows Vista reported to me:

Apache HTTP Server stopped working and was closed
A problem caused the application to stop working correctly. Windows will notify you if a solution is available*

Huh? It's not like I'm programming in C here, the server shouldn't just crash?

Trying to be Windows savvy, I open up the event log and find the following messages present:

Faulting application apache.exe, version, time stamp 0x493f5d44, faulting module ntdll.dll, version 6.0.6001.18000, time stamp 0x4791a7a6, exception code 0xc0000005, fault offset 0x0006814c, process id 0x1b88, application start time 0x01c98b2d160f9940.

Faulting application apache.exe, version, time stamp 0x493f5d44, faulting module php5ts.dll, version, time stamp 0x493d75fc, exception code 0xc00000fd, fault offset 0x000df44f, process id 0x698, application start time 0x01c98b2d16b3c880.

Well, that's not very useful. But, it was useful enough for me to Google around and find this article where someone had a similar problem. The bug turned out to be:

If you include a nonexistent helper in the AppController::$helpers array, infinite recursion occurs.

As you can probably guess, it's the infinite recursion part that gets you. Turns out, infinite recursion on Windows Apache + PHP (specifically using xampp) causes the server to crash. In fact, the issue can be reproduced with the following script:

function foo() {

I think it's absurd in this day and age that a process actually crashes ungracefully when you hit a stack overflow error like this. I mean, at the very least, can't you report that you've hit stack overflow so the programmer knows what the general problem is?

I went back through my code, and sure enough, a cut and paste error was resulting in infinite recursion. I updated the code and my problem was solved.

*In other words, "Don't call us, we'll call you"

No comments:

Post a Comment