3

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

3 Answers 3

1

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.

0

How about set_time_limit(3600);

In the beginning of your script? Would that work?

1
  • I had set that too. same result. Mar 29, 2012 at 14:42
0

is FCGI the apache handler? If it is, than you have to set the FcgidIOTimeout and FcgidBusyTimeout to a much higher value. You can place these directive in the apache config file(or in some cases in fcgi.conf or php.conf) after the fcgi module is loaded. You can find more information in apache fcgi documentation http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .