To prevent one of my task to hang, I would like to stop it after 3 seconds if not completed. What would be the best “server speed friendly” way to do this?
@NogDogApr 22.2007 — #You could use [url=http://www.php.net/set_time_limit]set_time_limit()[/url] to impose a maximum execution time on your script, although that's pretty brute force.
If you have some sort of loop going that might take too long, you could do something like: [code=php] $startTime = time(); $timeout = false; while(true) { if(time() - 3 > $startTime) { $timeout = true; break; } // do whatever needs doing in this loop } if($timeout) { // handle timeout error here } else { // loop completed under our time limit, so keep going normally } [/code]