Reply to Re: [PHP] Re: How to make a script sleep for 5 seconds?

Your name:

Reply:


Posted by "Richard Lynch" on 10/20/60 11:17

On Mon, May 30, 2005 7:17 pm, Peter Brodersen said:
> 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?

sleep(5);

> Easy:
> <?php
> for($i=0;$i<5;$i++) sleep(1);
> ?>
>
> Or better:
> <?php
> $endtime = time()+5;
> while (time() != $endtime);
> ?>

This runs the risk of somebody adding some code in there that takes longer
than a second to run, and then suddenly it's in an infinite loop because
the $endtime is never EQUAL to time()

Safe to say while (time() <= $endtime)

> Or even better:
> <?php
> $endtime = time()+5;
> while (`date +%s` != $endtime);

Gak!

Why would you shell out to do this?

> ?>
>
> 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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
Like Music?
http://l-i-e.com/artists.htm

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация