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

前端 未结 13 2520
时光说笑
时光说笑 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条回答
  •  囚心锁ツ
    2020-12-23 20:15

    Another example: You're running some sort of batch process that makes heavy use of a resource. Maybe you're walking the database of 9,000,000 book titles and updating about 10% of them. That process has to run in the middle of the day, but there are so many updates to be done that running your batch program drags the database server down to a crawl for other users.

    So you modify the batch process to submit, say, 1000 updates, then sleep for 5 seconds to give the database server a chance to finish processing any requests from other users that have backed up.

提交回复
热议问题