Re: Re: How to make a script sleep for 5 seconds?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2005-05-30 at 23:17, Richard Lynch wrote:
> On Mon, May 30, 2005 7:17 pm, Peter Brodersen said:
> > On Mon, 30 May 2005 21:08:29 -0400, in php.general
> > robert@xxxxxxxxxxxxx (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?

Mr. Lynch, either intentionally or inadvertently, you have succeeded in
making me spray water out my nose as I happened to be drinking a glass
of it when I read your reply :B

> > 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?

Definitely a PEAR candidate, but we should ensure it requires the
compatibility suite.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux