What is a practical use for PHP's sleep()?

前端 未结 13 2665
时光说笑
时光说笑 2020-12-23 19:17

I just had a look at the docs on sleep().

Where would you use this function?

Is it there to give the CPU a break in an expensive function?

Any common

13条回答
  •  旧时难觅i
    2020-12-23 20:08

    Among the others: you are testing a web application that makes ayncronous requests (AJAX calls, lazy image loading,...)

    You are testing it locally so responses are immediate since there is only one user (you) and no network latency.

    Using sleep lets you see/test how the web app behaves when load and network cause delay on requests.

提交回复
热议问题