note 110916 deleted from function.time-nanosleep by aharvey
| From: | aharvey@php.net | Date: | Tue, 08 Jan 2013 01:45:34 +0000 |
| Subject: | note 110916 deleted from function.time-nanosleep by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192784@lists.php.net to get a copy of this message | ||
Note Submitter: George at the-php-consultants dot com
----
I have a good delay instruction on windows. Other use a busy loop, I do not. Busy loops can be
exploited by hackers.
<?php
function nano_sleep($sec, $usec){
{
$start = gettimeofday();
for($i = 0;$timePassed / 100 < $usec;$i++){
$stop = gettimeofday();
$timePassed = 1000000 * ($stop['sec'] - $start['sec'])
+ $stop['usec'] - $start['usec'];
}
}
?>
This avoids the busy loop behaviour by using a for loop.