On my machine, the PHP program
<?php
$now= time();
echo "Now: ".$now."\n";
$waituntil= $now+5;
echo "Wait until: ".$waituntil."\n";
time_sleep_until($waituntil);
echo "Now: ".time()."\n";
?>
produces an output such as
Now: 1492614718
Wait until: 1492614723
Now: 1492614722
Now I am wondering why the time_sleep_until
function did not wait until the specified time (it always continues one second before the specified time).
How can I achieve that the program waits until the specified linux timestamp?
EDIT:
I added microtime(true)
and now get the following result:
<?php
$now= time();
$nowmicro= microtime(true);
echo "Now: ".$now."\n";
echo "Now micro: ".$nowmicro."\n";
$waituntil= $now+5;
echo "Wait until: ".$waituntil."\n";
time_sleep_until($waituntil);
$now= time();
$nowmicro= microtime(true);
echo "Now: ".$now."\n";
echo "Now micro: ".$nowmicro."\n";
?>
produces
Now: 1492616333
Now micro: 1492616333.1153
Wait until: 1492616338
Now: 1492616337
Now micro: 1492616338.0001