note 23932 deleted from function.sleep by dams
| From: | dams@php.net | Date: | Sat, 03 Aug 2002 03:04:26 +0000 |
| Subject: | note 23932 deleted from function.sleep by dams | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-34179@lists.php.net to get a copy of this message | ||
I tried to use the example function above to sleep under Windows but found that it pugged my CPU to
100% for the entire duration of the function. Since sleep() does not peg the CPU, I modified the
function to use sleep for the length of the number of whole seconds then use the rest of the
function for the left over fractions of a second. So the result is that the CPU is at most only
pegged for 1 second.
// this function is made because the built in
// sleep() function only takes integers
// and usleap() does not work in windows
//
// send pause() a float value of seconds
// like 1.9 seconds would be pause(1.9);
function pause($delay) // delay should be in seconds
{
//use sleep() because it does not peg the CPU
sleep(intval($delay));
// for any remaining fractional seconds, do the following
$micro_seconds=intval(($delay-intval($delay))*1000000);
$start = gettimeofday();
do {
$stop = gettimeofday();
$timePassed = 1000000 * ($stop['sec'] - $start['sec'])
+ $stop['usec'] - $start['usec'];
}
while ($timePassed < $micro_seconds);
}
// usage:
// sleep for 3.4 seconds
pause(3.4);