search

Home  >  Q&A  >  body text

Is sleep time included in the execution time limit?

<p>I have two questions about the <code>sleep()</code> function in PHP: </p> <ol> <li><p>Does sleep time affect the maximum execution time limit of PHP scripts? Sometimes, PHP displays the message "Maximum execution time exceeded 30 seconds". Will this message appear if I use <code>sleep(31)</code>? </p></li> <li><p>Are there any risks in using the <code>sleep()</code> function? Will it consume a lot of CPU performance? </p></li> </ol></p>
P粉766520991P粉766520991448 days ago698

reply all(2)I'll reply

  • P粉921130067

    P粉9211300672023-08-25 09:09:50

    In the PHP sleep() page, there are the following user-contributed comments:

    reply
    0
  • P粉674876385

    P粉6748763852023-08-25 00:17:27

    You should try this whenever you have a script that sleeps longer than the maximum execution time.

    <?php
      sleep(ini_get('max_execution_time') + 10);
    ?>

    Spoiler: Under Linux, sleep time is ignored, but under Windows, it counts as execution time.

    reply
    0
  • Cancelreply