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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...