Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php timeout - set_time_limit(0); - don't work

I'm having a problem with my PHP file that takes more than 30 seconds to execute.

After searching, I added set_time_limit(0); at the start of the code,cbut the file still times out with a 500 error after 30 seconds.

log: PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /xxx/xx/xxx.php  safe-mode : off 
like image 275
user614963 Avatar asked Aug 17 '12 04:08

user614963


People also ask

What does set_time_limit 0 mean?

Syntax: set_time_limit ( int $seconds ) Return Value: Boolean ( True or False ) Default value:30 seconds. For the maximum or you can say for the infinite execution time, we can set the function with the 0 value. If the value is 0 then it will run for an infinite time.

What is set_time_limit in PHP?

When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.

How do you fix maximum execution time of 60 seconds exceeded?

Just increase the max_execution_time in php. ini. Set it to 1800 and restart your apache or any other server you are using.


2 Answers

This is an old thread, but I thought I would post this link, as it helped me quite a bit on this issue. Essentially what it's saying is the server configuration can override the php config. From the article:

For example mod_fastcgi has an option called "-idle-timeout" which controls the idle time of the script. So if the script does not output anything to the fastcgi handler for that many seconds then fastcgi would terminate it. The setup is somewhat like this:

Apache <-> mod_fastcgi <-> php processes 

The article has other examples and further explanation. Hope this helps somebody else.

like image 45
Paul Avatar answered Oct 08 '22 14:10

Paul


Check the php.ini

ini_set('max_execution_time', 300); //300 seconds = 5 minutes  ini_set('max_execution_time', 0); //0=NOLIMIT 
like image 119
user1601782 Avatar answered Oct 08 '22 14:10

user1601782