Welcome to WebmasterWorld Guest from 54.160.254.203

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Problem with maximum execution time

     
9:01 pm on Aug 27, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 7, 2004
posts:88
votes: 0


I need to run a script which will take several minutes to complete, but the max execution time is 30 seconds and I cannot change that value.

Is there some way to detect the elapsed execution time of a script, in order to suspend it automatically and prevent the timeout?

Thanks in advance!

2:47 am on Aug 28, 2007 (gmt 0)

Senior Member from MY 

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 1, 2003
posts:4847
votes: 0


set_time_limit(0); removes the limitation altogether
set_time_limit(X); sets the time limit to X

To detect run-time, use something like this:

<?php
$start=time();
while (($long_slow_loop)&&(time()<($start+25)))
{
...
...
}
?>

The 25 allows 5 seconds spare, you may wish to cut it finer depending on how fast your loop runs.
6:01 pm on Aug 28, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 7, 2004
posts:88
votes: 0


Thanks, I'll try that.