note 55802 added to function.time-nanosleep

From: Date: Sat, 13 Aug 2005 21:03:19 +0000
Subject: note 55802 added to function.time-nanosleep
Groups: php.notes 
Request: Send a blank email to php-notes+get-93566@lists.php.net to get a copy of this message
You should take into account, if you use the function replacement down here, the CPU will be in use of 99% for the time of execution... (A little bit better in this situation is to let the 'full seconds' go by a normal sleep command (makes the thread sleep!, and uses minimum cpu)) <?php //THIS IS THE FUNCTION WE ARE TALKIN ABOUT function timeWait($microtime) { //optimizations added by me [start] //sleep the full seconds sleep(intval($microtime)); //set the microtime to only resleep the last part of the nanos $microtime = $microtime - intval($microtime); //optimizations added by me [end] $timeLimit = $microtime + array_sum(explode(" ",microtime())); while(array_sum(explode(" ",microtime())) < $timeLimit) {/*DO NOTHING*/} return(true); } //THIS IS HOW WE CAN USE IT echo "Process started at " . date("H:i:s") . " and " . current(explode(" ",microtime())) . " nanoseconds.<br>"; timeWait(5.5); //With this call the system will wait 5 seconds and a half. You can use either integer or float. echo "Process completed at " . date("H:i:s") . " and " . current(explode(" ",microtime())) . " nanoseconds."; ?> ---- Manual Page -- http://www.php.net/manual/en/function.time-nanosleep.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55802 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55802&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55802&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55802&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55802&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55802&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55802&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55802&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93566) next »