If I want to suspend code execution in PHP do I use sleep()?
If so, what exactly happens on the client side while the number of seconds passed to sleep() are running? Nothing? It just waits for a response from the webserver? Or does it tell the browser – “OK, I got your request, but you will have to wait X seconds until I send you a response.” ?
Thank you.
sleep() simply suspends the script for the specified time interval. Internally it tells the OS “I’m going to sleep, wake me in X seconds”. Unless the PHP script outputs a message to the client-side browser that it is going to sleep, the browser will simply hang until it decides the connection’s dead, the network connection dies from lack of activity, or your script wakes up and resumes operations. sleep() is a purely server-side operation, and does NOT change anything on the client.