Difference among sleep() and usleep() in PHP

前端 未结 5 1461
执笔经年
执笔经年 2021-01-07 17:35

Can any body explain me what is the difference among sleep() and usleep() in PHP.

I have directed to use following scripts to do chat appli

相关标签:
5条回答
  • 2021-01-07 18:09

    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.

    0 讨论(0)
  • 2021-01-07 18:09

    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
    0 讨论(0)
  • 2021-01-07 18:11

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

    0 讨论(0)
  • 2021-01-07 18:14

    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?
    
    0 讨论(0)
  • 2021-01-07 18:26

    Simply

    usleep uses CPU Cycles while sleep does not.

    sleep takes seconds as argument

    while usleep takes microseconds as argument

    0 讨论(0)
提交回复
热议问题