Does sleep time count for execution time limit?

caw picture caw · Apr 12, 2009 · Viewed 28.2k times · Source

I have two questions concerning the sleep() function in PHP:

  1. Does the sleep time affect the maximum execution time limit of my PHP scripts? Sometimes, PHP shows the message "maximum execution time of 30 seconds exceeded". Will this message appear if I use sleep(31)?

  2. Are there any risks when using the sleep()function? Does it cost a lot of CPU performance?

Answer

Samuel picture Samuel · Apr 12, 2009

You should try it, just have a script that sleeps for more than your maximum execution time.

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

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