Skip to content
PHP Logo

Are there specific scenarios where using sleep() in PHP is recommended?

Using sleep() in PHP can be useful in scenarios where you need to delay the execution of a script for a certain amount of time. This can be helpful for simulating real-world delays, controlling the rate of API requests, or creating timed events in a script.

php
// Delay script execution for 5 seconds
sleep(5);

// Continue with the rest of the script
echo "Script execution resumed after 5 seconds.";