ballhogjoni Posted January 5, 2009 Share Posted January 5, 2009 Can I do that like this?: <?php for($i=0;$i<=10;$i++){ echo 'this is something '.$i; } //some more php code would go here before the entire script is finished executing. ?> Quote Link to comment https://forums.phpfreaks.com/topic/139582-is-there-a-way-to-send-info-to-a-browser-during-a-loop/ Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 Only works on some browsers <?php for($i=0;$i<=10;$i++){ echo 'this is something '.$i; ob_flush(); flush(); } ?> ob_flush and flush Quote Link to comment https://forums.phpfreaks.com/topic/139582-is-there-a-way-to-send-info-to-a-browser-during-a-loop/#findComment-730193 Share on other sites More sharing options...
ballhogjoni Posted January 5, 2009 Author Share Posted January 5, 2009 yep I tried that too. It didn't work...I am using firefox, would that be why? Quote Link to comment https://forums.phpfreaks.com/topic/139582-is-there-a-way-to-send-info-to-a-browser-during-a-loop/#findComment-730195 Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 yep I tried that too. It didn't work...I am using firefox, would that be why? Well a loop of 10 would not really show this. It works in Firefox cause that is what I use and I know it works...try this. <?php set_time_limit(100); for($i=0;$i<=10;$i++){ echo 'this is something '.$i; ob_flush(); flush(); sleep(5); } ?> It should take display that every 5 seconds. Along with the browser difference, I know that some Anti-virus software will hold your page buffer until the end then display it, so that is also something to think about/check. Quote Link to comment https://forums.phpfreaks.com/topic/139582-is-there-a-way-to-send-info-to-a-browser-during-a-loop/#findComment-730199 Share on other sites More sharing options...
PFMaBiSmAd Posted January 5, 2009 Share Posted January 5, 2009 Php, different web servers and different web server settings for buffering and compression, and different browsers and different browser settings for compression affect if and when you can incrementally send output from a server to a browser. You should not expect a web based application to be able to do this from the server side. If you get it working on one setup, it probably won't work on the next. To get a value to update in the browser, you should have the browser get that value from the server using AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/139582-is-there-a-way-to-send-info-to-a-browser-during-a-loop/#findComment-730209 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.