🙂
Can not get this Delay function to work
It is supposed to Delay for any number of seconds
I have written a 'test' program, but this will display only:
Timer is started
Please wait ...
but nothing more happens
<?php
// To speed up program execution
// and avoid timing errors
// I turn error check reporting OFF
//
error_reporting(0);
///////// functions ////////////////////
// Get microtime, with microsecond precision
//
function mtimes(){
return array_sum(explode(" ",microtime()));
}
// Delay $s number of seconds
// If no value, wait 1 sec
//
function waitsec($s=1){
$a=array_sum(explode(" ",microtime()));
while(array_sum(explode(" ",micortime()))-$a<$s);
}
///////// test /////////////////////////
echo '<body>';
echo 'Timer is started<br>Please wait ...<br><br>';
$beg = mtimes(); // start stopwatch timer
$lop = 5; // 5 loops x 2 seconds
for ($i=0;$i<$lop;$i++){
waitsec( 2 ); // delay 2 sec function
}
$end = mtimes(); // stop stopwatch
// Round and Display time in seconds
// Result should be 10 seconds delay = 5 x 2
$delay_sec = $end - $beg;
// Round to 7 decimals for display
$displaydelay = float( round( $delay_sec,7 ) );
echo "Delay was exactly<b> $display_delay </b>seconds";
echo '</body>';
exit;
///////// end test /////////////////////////
?>
What is problem here?
😕