PHP Sleep Milliseconds: Timestamp Guide
In PHP, you can use the usleep() function to make a script sleep for a specified number of microseconds. If you want to make the script sleep for a number of milliseconds, you can convert the milliseconds to microseconds. Below is an example code:
// 要休眠的毫秒数
$milliseconds = 1000; // 1秒
// 将毫秒数转换为微秒数
$microseconds = $milliseconds * 1000;
// 休眠指定的微秒数
usleep($microseconds);
echo "脚本休眠了 $milliseconds 毫秒";
In the examples above, we convert the number of milliseconds we want to sleep into microseconds and use the usleep() function to put the script to sleep for the specified number of microseconds.