php 500 error with no log entry!?!?!?

Every so often I run across an a 500 error on a production system that has no apparent cause. The application logs, nor the server logs, nor the php specific logs will have any clue to the cause. It is incredibly frustrating.

Every time I start combing through code that I suspect of causing this issue, and every time I come up empty. After flailing around for what seem forever and reading everything I can Duck Duck Go or Google, I have an idea... maybe it ran out of memory. It never fails, this has been the case and yet I seem to forget this lesson. (Note: I have gotten an over memory limit entry in the log once or twice after trying the same action many times, but it is rare.)

I just go into my php.ini and update the memory_limit=xxxM to some higher value. This is never the end of the story but it is a giant clue to the root of the issue. I am not sure why this does not produce a log entry. I genereally run php web applications through apache with fcgi and suexec. If I was to venture to guess, the php thread was checking itself for memory usage and automatically killing itself when reaching this limit before writing a log. Considering I have gotten a log entry very rarely, I would tend to believe there is a race condition between writing the entry and terminating the script, but I would love to know the truth.

High memory usage is many times, but not always. a symptom of a larger issue: poorly written code. Commonly, I have found this issue to crop up when a chunk of code loads an entire database table (or tables) into memory and runs a calculation or ACL check verses the results. This out of memory issue does not present when working in a dev enviroment with a smaller data set, but can easly crop up randomly once the application is deployed. 

Tags: website, php, 500

Contact Us To Setup A Meeting

Feel free to call or email anytime to setup a meeting. We would love to discuss your project to see if we can help!

contact us