note 30761 modified in function.gettimeofday by didou
| From: | didou@php.net | Date: | Tue, 06 Jul 2004 21:25:40 +0000 |
| Subject: | note 30761 modified in function.gettimeofday by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72795@lists.php.net to get a copy of this message | ||
The solution above has a bug due to cycling 'usec' in range of 0 to 999999 with period of
one second. True timing could be as something:
<?php
function get_timer()
{
$t=gettimeofday();
return (double)($t['sec'].'.'.sprintf("%06d",
$t['usec']));
}
$wakeup=get_timer()+$delay;
while(get_timer()<$wakeup);
?>
'sec' is UNIX seconds from 1/1/1970 (absolute time) and such way is no matter of cycling
millimicroseconds between seconds (change of $t['usec'] from '999999' to
'0' with one $t['sec'] increment) and seconds themselves between days (change of
23:59:59 to 0:00:00)
jz
--was--
The solution above has a bug due to cycling 'usec' in range of 0 to 999999 with period of
one second. True timing could be as something:
function get_timer()
{
$t=gettimeofday();
return (double)($t['sec'].'.'.$t['usec']);
}
$wakeup=get_timer()+$delay;
while(get_timer()<$wakeup);
'sec' is UNIX seconds from 1/1/1970 (absolute time) and such way is no matter of cycling
millimicroseconds between seconds (change of $t['usec'] from '999999' to
'0' with one $t['sec'] increment) and seconds themselves between days (change of
23:59:59 to 0:00:00)
jz
http://php.net/manual/en/function.gettimeofday.php