note 23932 added to function.sleep

From: Date: Thu, 01 Aug 2002 17:19:30 +0000
Subject: note 23932 added to function.sleep
Groups: php.notes 
Request: Send a blank email to php-notes+get-34098@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); -- http://www.php.net/manual/en/function.sleep.php http://master.php.net/manage/user-notes.php?action=edit+23932 http://master.php.net/manage/user-notes.php?action=delete+23932 http://master.php.net/manage/user-notes.php?action=reject+23932

« previous php.notes (#34098) next »