微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 何时使用time_nanosleep?

偶然发现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以微秒(数千纳秒)指定,因此对于一些非常小的睡眠间隔,它的基本单位可能太大.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐