|
Posted by Peter Brodersen on 10/21/71 11:17
On Mon, 30 May 2005 21:08:29 -0400, in php.general
robert@interjinn.com (Robert Cummings) wrote:
>Sorry to hijack this thread but I was wondering how to make a script
>sleep for 5 seconds?
Easy:
<?php
for($i=0;$i<5;$i++) sleep(1);
?>
Or better:
<?php
$endtime = time()+5;
while (time() != $endtime);
?>
Or even better:
<?php
$endtime = time()+5;
while (`date +%s` != $endtime);
?>
We have busy wait, we have risk of indefinite loops. The next step
should be (more) imprecision. Maybe read /proc/cpuinfo and perform n
steps of simple loop where n is calculated from the cpu type, mhz and
current load. Maybe a PEAR project?
--
- Peter Brodersen
Navigation:
[Reply to this message]
|