The sleep () function is generally used on pauses, but once PHP has sleep, the rest of the output (Print,echo) waits for the sleep () function to complete, because the buffer is explained in detail here.
Do not repeat here, and if you want to achieve the first output and then wait for the output, then use the Ob_flush () and flush ();
The above linked article has such a paragraph explaining why it is necessary to Ob_flush () and flush ();
When the cache is not turned on, the contents of the script output are in the state of waiting for output on the server side, and flush () can send the content waiting for output to the client immediately.
When the cache is turned on, the contents of the script output are stored in the output cache, and there is no content waiting for the output state, and you directly use flush () without sending anything to the client. The function of Ob_flush () is to remove the contents of the output cache, set to wait for the output state, but not directly to the client, you need to use Ob_flush () and then flush () before the client can immediately get the output of the script.
So the code is like this
<? PHP Echo Date (' h:i:s '). ' </br> '; Ob_flush (); Flush (); Sleep (5); Echo Date (' h:i:s ');? >
How PHP uses sleep to implement output--wait-and-output