php——–暂停函数 sleep() 与 usleep() 的区别(PHP ——- the difference between the pause function sleep() and usleep())


注意:usleep()单位是微秒,1秒 = 1000毫秒 ,1毫秒 = 1000微秒,即1微秒等于百万分之一秒。

如果程序中要使用要暂停多少毫秒,只能使用usleep(),务必注意参数的单位,假设暂停 50毫秒,应该使用 usleep(50000),而不是usleep(50)。



In PHP, pause code execution for a certain period of time. There are two functions that can be implemented, one is sleep (), the other is usleep (), and their parameters are an integer value. Sleep () is the number of seconds to pause and usleep () is the number of microseconds to pause.

< strong > note: the unit of usleep () is microseconds, 1 second = 1000 milliseconds, 1 millisecond = 1000 microseconds, that is, 1 microsecond is equal to one millionth of a second

If you want to use the number of milliseconds to pause in the program, you can only use usleep (). Be sure to pay attention to the unit of the parameter. If you pause for 50 milliseconds, you should use usleep (50000), not usleep (50).

In addition, this pause cannot be 100% accurate, which has a certain relationship with the system scheduling, CPU clock cycle, etc.