note 110916 modified in function.time-nanosleep by googleguy
| From: | googleguy@php.net | Date: | Sat, 22 Dec 2012 23:03:09 +0000 |
| Subject: | note 110916 modified in function.time-nanosleep by googleguy | ||
| References: | 1 | Groups: | php.notes php.notes |
| Request: | Send a blank email to php-notes+get-192654@lists.php.net to get a copy of this message | ||
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.
--was--
I have a good delay instruction on windows. Other use a busy loop, I do not. Busy loops can be
exploited by hackers.
[code]
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'];
}
}
[/code]
This avoids the busy loop behaviour by using a for loop.
http://php.net/manual/en/function.time-nanosleep.php