0

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

  • Without actual code it is rather difficult to tell ehat may have gone wrong. You have to do your own debugging first and narrow down the problem to particular sections of the code and then share those sections with us. – Shadow Feb 16 '17 at 02:15

2 Answers2

0

You're more than likely running into issues with your webserver. If it's apache, then there is the Timeout Directive. You may also be running into memory issues, which again has settings both in php.ini and apache. But without some more detail.. I'm afraid that's as much as I can offer.

redreinard
  • 1,994
  • 1
  • 19
  • 25
-1

If you are using Wordpress , Probably some syntax error. run you code in development mode. you will see error. Otherwise it keep showing 500 error.