I am encountering this really weird 500 Internal Server Error (End of script output before headers). It happens when I try to execute a .php File which takes fairly long to run. I've taken precautions by adding set_time_limit(120); ini_set('max_execution_time', 120);
to the file. 2 minutes should suffice. I've also declared header('Content-Type: text/plain');
.
Now the weird thing is - most of the time, the code actually fully executes, everything up until the last exit();
has definitely executed (I can't check if that last exit does thoug). However, I still get a 500 Internal Server Error (log says End of script output before headers
).
Even weirder is, if I run the file a second time within maybe 5-10 minutes, it all runs perfectly fine. And sometimes, the code just stops in the middle of things and throws the error.
If it matters, when the script stops in the middle, it is usually in a foreach loop while reading items from an xml file and writing them to a csv file. It's always when a loop is done.
I really do not have any clue why this happens.
Any help would be appreciated.
Thank you very much,
fraeckey