Re: Interesting sleep() side-effect

From: Date: Thu, 28 Jan 1999 07:57:41 +0000
Subject: Re: Interesting sleep() side-effect
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-3749@lists.php.net to get a copy of this message
It's fine actually. Our timer times actual CPU time, not real time. sleep() does not consume any CPU time, so the script will not timeout for quite a while. This is actually quite intentional... Zeev At 00:49 27/01/99 -0500, Rasmus Lerdorf wrote: >In testing Thies' connection abort detection code, completely unrelated to >his stuff, I noticed an interesting side-effect of calling sleep() in a >PHP script. I have tried this on both Linux and Solaris and get the same >results. Could you guys with access to other OS'es try this one? > ><? > set_time_limit(5); > register_shutdown_function("done"); > function done() { > global $i; > > $fp = fopen("/tmp/done","w"); > fputs($fp,"i reached $i\n"); > fclose($fp); > } > > for($i=0; $i<30000; $i++) { > for($j=0;$j<1000;$j++) $a=sqrt($j); > /* sleep(1); */ > echo "$i > ................................................................................<br>"; > flush(); > } >?> > > >This script should run for 5 seconds, unless of course you are on a >massively fast machine that can do 30000 sqrt()'s in 5 seconds. However, >when you uncomment the sleep(1) call there, it will happily run way past 5 >seconds. Looks to me like the sleep() system call is interfering with our >itimer. The man pages state that sleep() may be implemented as a SIGALRM, >but we are using a SIGPROF itimer, so I thought we were actually safe >here. > >It doesn't worry me too much. It is more an interesting side effect, but >something we might want to document as a caveat in the sleep() >documentation. I would be intersted in hearing if this behaviour is >consistent across all the operating systems. > >The "/tmp/done" file is not related to this particular message. That's >just how I am testing to see if PHP catches when the client closes the >socket. > >-Rasmus > > >-- >PHP Development Mailing List http://www.php.net/ >To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net >For help: php-dev-help@lists.php.net > > > -- Zeev Suraski <zeev@zend.com> http://www.zend.com/ For a PGP public key, finger bourbon@netvision.net.il -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#3749) next »