Difference among sleep() and usleep() in PHP

与世无争的帅哥 提交于 2019-12-01 02:14:20

The argument to sleep is seconds, the argument to usleep is microseconds. Other than that, I think they're identical.

sleep($n) == usleep($n * 1000000)

usleep(25000) only sleeps for 0.025 seconds.

Ashwin

sleep() allows your code to sleep in seconds.

  • sleep(5); // sleeps for 5 seconds

usleep() allows your code with respect to microseconds.

  • usleep(2500000); // sleeps for 2.5 seconds
shahpranaf

usleep() is used to delay execution in "microseconds" while sleep() is used to delay execution in seconds. So usleep(25000) is 0.025 seconds.

Is there any difference between the two?

Simply

usleep uses CPU Cycles while sleep does not.

sleep takes seconds as argument

while usleep takes microseconds as argument

One other difference is sleep returns 0 on success, false on error. usleep doesn't return anything.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!