问题描述
sleep(1); #waits/sleeps for one second then continue running the script
Q1.如何使这1/100秒呢?以下哪项有效:0,01
或0.01
或.01
?
Q1. How to make this 1/100 of a second? which of these work: 0,01
or 0.01
or .01
?
Q2.什么是替代品? wait();
或snap();
??它们有何不同(精确度更高/更低)?
Q2. What are alternatives? wait();
or snap();
?? how do they differ (more/less precise)?
推荐答案
以上都不是!
usleep
是您想要的瞬间. usleep(100000)
会睡眠十分之一秒.
usleep
is what you want for fractions of a second. usleep(100000)
will sleep for one tenth of one second.
您的其他选项是 time_nanosleep
,秒和令人难以置信的纳秒(其中十亿分之一秒),以及 time_sleep_until
,它将休眠直到达到特定的unix时间戳.
Your other options are time_nanosleep
which takes both seconds and freaking nanoseconds (one billion of which are one second), and time_sleep_until
, which will sleep until a particular unix timestamp has been reached.
请注意,您的系统可能没有毫秒级的分辨率,不少于十亿分之一秒的分辨率.您可能很难在极短的时间内睡着.
Be aware that your system might not have millisecond resolution, no less nanosecond resolution. You might have trouble sleeping for precisely tiny, tiny amounts of time.
这篇关于如何使用SLEEP()函数在PHP中暂停脚本几分之一秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!