如何使用SLEEP()函数在PHP中暂停脚本几分之一秒? [英] How to pause a script just for a fraction of a second in PHP using the SLEEP() function?

查看:234
本文介绍了如何使用SLEEP()函数在PHP中暂停脚本几分之一秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sleep(1);   #waits/sleeps for one second then continue running the script

Q1.如何使这1/100秒呢?以下哪项有效:0,010.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)?

推荐答案

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 ?

以上都不是!

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 ,秒和令人难以置信的纳秒(其中十亿分之一秒),以及

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中暂停脚本几分之一秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆