Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Script Times out after 45 seconds

Tags:

php

timeout

I am running a huge import to my database(about 200k records) and I'm having a serious issue with my import script timing out. I used my cell phone as a stop watch and found that it times out at exactly 45 seconds every pass(internal server error)... it only does about 200 records at a time, sometimes less. I scanned my phpinfo() and nothing is set to 45 seconds; so, I am clueless as to why it would be doing this.

My max_execution_time is set to 5 minutes and my max_input_time is set to 60 seconds. I also tried setting set_time_limit(0); ignore_user_abort(1); at the top of my page but it did not work.

It may also be helpful to note that my error file reads: "Premature end of script headers" as the execution error.

Any assistance is greatly appreciated.

like image 316
Dave C Avatar asked Apr 23 '10 16:04

Dave C


People also ask

How can you increase the maximum execution time of a script in PHP?

To increase the script execution time, you can use the following snippet at the top of your script. ini_set ( 'max_execution_time' , '300' ); In the above example, it would set the max_execution_time directive to 300 seconds.

What is set time limit in PHP?

The set_time_limit() function lets you set how long a script should be allowed to execute. This value is usually set inside php. ini under the max_execution_time setting; however, you can override that here. The function takes one parameter, which is the number of seconds you want the script to have.


1 Answers

I tried all the solutions on this page and, of course, running from the command line:

php -f filename.php

as Brent says is the sensible way round it.

But if you really want to run a script from your browser that keeps timing out after 45 seconds with a 500 internal server error (as I found when rebuilding my phpBB search index) then there's a good chance it's caused by mod_fcgid.

I have a Plesk VPS and I fixed it by editing the file

/etc/httpd/conf.d/fcgid.conf

Specifically, I changed

FcgidIOTimeout 45

to

FcgidIOTimeout 3600

3600 seconds = 1 hour. Should be long enough for most but adjust upwards if required. I saw one example quoting 7200 seconds in there.

Finally, restart Apache to make the new setting active.

apachectl graceful

HTH someone. It's been bugging me for 6 months now!

Cheers,

Rich

like image 145
Rich Avatar answered Oct 15 '22 15:10

Rich