Several days ago, all mail()
calls in my custom PHP application cause a 500 Internal Server Error
and the only error logged is Premature end of script headers
. Running the file via SSH sometimes returns a segfault
. The strange thing is no code changed between the time when the mail()
call worked, and stopped working (changes are tracked in Git).
Even though no changes were made to the code, I still went through and did the normal checks (.htaccess, php.ini, custom error handler, etc), just to be safe.
I attempted to diagnose the problem by cutting out code in the application until the issue was pinpointed. However, this did not narrow it down to a specific piece of code, but rather the amount of code loaded into PHP (but not yet run) as the time of the mail()
call.
In the trimmed application, I was able to get one mail()
call to work, but the second would fail. The first call was immediately before an include
call (require
has same outcome). The second was at the very beginning of the included file (preceded only be the opening PHP tags).
My original thoughts were it was some sort of memory issue. Oddly, the memory usage required to cause the mail()
call to throw an error changes based on which code is kept/removed from the overall application. In case it can still help, the memory usage for the current collection of code before including the file is:
Usage: 3113696
Max: 3352560
The memory usage after including the file is still unknown.
I've spoken to my host about the issue, and they claim nothing has changed that would cause this issue.
I have not been able to reproduce this issue in other applications.
Technologies Used
- PHP 5.3.10 (5.2.17 also affected)
- MySQLi (specifically custom class extending MySQLi)
- Suhosin Patch 0.9.10
Error Messages Logged
- Premature end of script headers: XXX, referer: XXX
TL;DR
What would cause my PHP application to start causing 500 Internal Server Errors
when mail()
is called after a certain point in the code (but not after any specific call) without any PHP code being changed?
Additional Notes
- Not a timeout issue - takes less than a second to load
- Not a memory limit issue - only using ~3MB when it crashes, but I have a 99MB limit