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>'; } 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 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. 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! 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
Archived
This topic is now archived and is closed to further replies.