I've been learning about long-polling and after reading a little about it, find myself a bit confused. I looked at explanations here and here
I don't quite understand what the point is in making the server sleep prior to responding. I know the idea is to try to keep the connection open between the client and server, but in the 2nd link with the highest upvoted php example, it has a code snippet where the server just calls sleep for some amount of time.
<?php
/* Send a string after a random number of seconds (2-10) */
sleep(rand(2,10));
echo("Hi! Have a random number: " . rand(1,10));
?>
What exactly does the sleep accomplish? Doesn't that just make it so that every time you send a request, it will simply sleep first (making the server do nothing), then respond, making it exactly like a standard http request but much slower? I don't see how it helps to maintain a connection if the sleep just makes the server do nothing for some amount of time. Isn't the point of long polling to respond to the client whenever new information is received?