stijn0713 Posted January 15, 2013 Share Posted January 15, 2013 This little experiment totally blew my mind. Apparently the number are only echoed when the for loop in completely ended. Why is this and how can i obtain a number being printed after the number's amount in seconds? for( $y=0; $y<=10; $y++ ){ sleep($y); echo $y.'<br>'; } Quote Link to comment https://forums.phpfreaks.com/topic/273207-sleep-in-for-while-loop/ Share on other sites More sharing options...
premiso Posted January 15, 2013 Share Posted January 15, 2013 (edited) The reasoning is because the browser holds all output until the end of processing to display a complete document, or the content is flushed. However, flushing only works on some browsers. Take a look at flush and ob_flush to learn more about flushing. If this was ran in CLI (command line interface), you would see the output as expected. Edited January 15, 2013 by premiso Quote Link to comment https://forums.phpfreaks.com/topic/273207-sleep-in-for-while-loop/#findComment-1405940 Share on other sites More sharing options...
stijn0713 Posted January 15, 2013 Author Share Posted January 15, 2013 thanks! Quote Link to comment https://forums.phpfreaks.com/topic/273207-sleep-in-for-while-loop/#findComment-1405964 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.