Re: escape loop on timeout

From: Date: Tue, 22 May 2001 09:53:50 +0000
Subject: Re: escape loop on timeout
References: 1 2  Groups: php.windows 
Request: Send a blank email to php-windows+get-7810@lists.php.net to get a copy of this message
Johan Lundqvist wrote: > This is a way of doing it: > > $s = time() + 10; > for ($i = time(); $i <= $s; $i++) { > print $i; > } > > Will run for about ten seconds... Did you leave a bit of code out? In most cases, this will run for only a few milliseconds. :) Try something like this instead: $timeout = 1; // Timeout in seconds $start_time = time(); // Get the current time for ($x=0; $x < 1000000000; ++$x) { /* // Check if we have gone over the time limit // Only check every 1000 loops - this keeps // us from chewing run time by checking the time // all the time :) */ if ( (0 === ($x % 1000)) && (time () - $start_time) > $timeout) break; echo ($x, '<br>'); } --zak

« previous php.windows (#7810) next »