Answer the question
In order to leave comments, you need to log in
How to make script execution delay < 10 milliseconds?
There is a loop, inside the usleep() function pauses the execution of each iteration for a given number of microseconds (millionths of a second). I want the script to pause for 10 milliseconds (i.e. 10 thousandths of a second). Looks like this:
for($i = 1; $i <= 1000; $i ++){
/*
* какой-то код
*/
usleep(10000); //это 0,010 секунды
}
Answer the question
In order to leave comments, you need to log in
$lastTime = microtime(true);
for($i = 1; $i <= 1000; $i ++){
while (true)
{
$new_last = microtime(true);
if ($new_last - $lastTime > 0.010)
{
$lastTime = $new_last;
break;
}
}
/*
* какой-то код
*/
}
I became curious, php went to remember
this code from me:
var_dump(number_format(microtime(true), 6));
time_nanosleep(0, 10 * 1000 * 1000);
echo "<br />";
var_dump(number_format(microtime(true), 6));
output the following:string(20) "1,396,895,032.113305"
string(20) "1,396,895,032.123673"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question