Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to run a long php process and it ends with the 500 internal server error. It executes fine for about 8 mins. I have rebooted the machine after changing the php settings.

PHP Config:

max_execution_time: 3600

After around 10 mins ps ax|grep php:

19007 ? S 0:08 /usr/bin/php /home/gypsy/public_html/index.php

I have set the ignore_user_abort true.

The process gets stuck at 00:08(8th minute) and isn't executed further.

Apache error log shows the error:

Script timed out before returning headers: index.php

It seems somehow the max_execution_time isn't working. Any suggestion would be a great help.

Update:

I have been able to detect the problem. It's the firewall that was blocking the process. the server is using iptables with configserver as firewall. Disabling the firewall works fine. But I am not sure which settings to change to allow the long running process in the firewall

share|improve this question

2 Answers 2

Whenever i see "headers"-errors i check back whether

  1. There is any output buffering active
  2. There is already any headers generated

Before any place of possible failure and/or forwarding in the code may take place. Last resort sometimes is to step through the stages of the script like this:

var_dump($runtimeStuffInfo);die('argh!');

and narrow down the area code where the problems starts occuring. You're not quite saying what your "8-minute-script" is trying to do, but from my experience the most stable approach would be to stick to CLI for this kind of things:

Ideally it is possible for you to to logon to your server via SSH and run the script from the command line (preferably via nohup so you don't have to care if the connection breaks) - this way you would also always see where your script stops (in case it would still do) as you can log each and every bit straightaway as it is echoed out to the console.

If you don't own permissions to login via SSH, you could still try to exec ('nohup php long_running_job.php > /some/writable/directory/with766/your_job.log') to trigger your job in one PHP page (e.g. http://example.com/startjob.php) and then you parse the output of your cronjob from your_job.log in another script page (e.g. http://example.com/jobresults.php).

In case even all of the above that doesn't get you there, i'd break up the job up in smaller chunks of work that will finish long before your timeout problem can occur, and then just call them one after another.

share|improve this answer

How about set_time_limit(3600);

In the beginning of your script? Would that work?

share|improve this answer
    
I had set that too. same result. –  Sabirul Mostofa Mar 29 '12 at 14:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.