vinpkl Posted May 21, 2015 Share Posted May 21, 2015 Hi If i run the below script then both the dates are displayed after delay of 15 seconds. But i think 1st date should get displayed instantly and 2nd should get display after 15 seconds. But its not happening ?? <?php echo date('H:i:s'); sleep(15); echo "<br>"; echo date('H:i:s'); ?> Vineet Quote Link to comment https://forums.phpfreaks.com/topic/296436-how-does-sleep-function-works/ Share on other sites More sharing options...
Ch0cu3r Posted May 21, 2015 Share Posted May 21, 2015 But i think 1st date should get displayed instantly and 2nd should get display after 15 seconds. No. It will halt the script for 15 seconds, then the two dates will be shown. This is because by default PHP buffers the output which is then output all at once to the browser. However if you ran this script form the command line then yes, it will echo the first date and then 15 seconds later output the second date. If you want the contents to be streamed in the browser then you need to flush the buffer. Have a read of the following article for more info. http://www.sitepoint.com/php-streaming-output-buffering-explained/ Quote Link to comment https://forums.phpfreaks.com/topic/296436-how-does-sleep-function-works/#findComment-1512387 Share on other sites More sharing options...
vinpkl Posted May 21, 2015 Author Share Posted May 21, 2015 Hi Ch0cu3r Thanks for the explanation vineet Quote Link to comment https://forums.phpfreaks.com/topic/296436-how-does-sleep-function-works/#findComment-1512390 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.