加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 何时使用time_nanosleep?

发布时间:2020-12-13 17:11:46 所属栏目:PHP教程 来源:网络整理
导读:偶然发现time_nanosleep()并开始怀疑,你什么时候想要使用它? 此外,甚至可以在像PHP这样的脚本语言中使用这么短的时间跨度吗? 解决方法 不,它永远不可能使用单纳秒.只有Linux中的上下文切换通常在几百纳秒内,不包括Zend引擎的开销. 我检查了PHP源代码,它只
偶然发现time_nanosleep()并开始怀疑,你什么时候想要使用它?

此外,甚至可以在像PHP这样的脚本语言中使用这么短的时间跨度吗?

解决方法

不,它永远不可能使用单纳秒.只有Linux中的上下文切换通常在几百纳秒内,不包括Zend引擎的开销.

我检查了PHP源代码,它只是一个围绕C nanosleep函数的简单包装器. nanosleep的手册页说:

nanosleep() suspends the execution of the calling thread until
either at least the time specified in *req has elapsed

Compared to sleep(3) and usleep(3),nanosleep() has the following
advantages: it provides a higher resolution for specifying the
sleep interval

所以这就是你要指定间隔的小小.由于usleep以微秒(数千纳秒)指定,因此对于一些非常小的睡眠间隔,它的基本单位可能太大.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读