bluesoul Posted November 25, 2008 Share Posted November 25, 2008 Okay, I'm trying to give a summary of a loop in progress in the browser window, and the results are unexpected to say the least. The relevant code is: for($i = 0; $i < $j; $i++) { if($i%10) { sleep(3); echo("Processed $i domains of $j...\r\n"); flush(); set_time_limit(30); } (do stuff here) } Generally it'll only spit out updates every 30 seconds or so instead of every 3 seconds which should be all it takes to get to 10 iterations of the loop, it involves sending an email and I don't want to overload the server, hence the sleep(). I'm sure there's a better function than flush for this but I haven't been able to get any results out of anything else. Thanks. Link to comment https://forums.phpfreaks.com/topic/134221-flushing-to-browser/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 25, 2008 Share Posted November 25, 2008 The whole Internet is not designed to incrementally output content from the web server to the browser. It ties up one of the available server connections for the duration of the task. The best ways to do what you want is to either cause the page to refresh itself perodically or use AJAX to perodically request the information and display it without refreshing the whole page. Link to comment https://forums.phpfreaks.com/topic/134221-flushing-to-browser/#findComment-698641 Share on other sites More sharing options...
bluesoul Posted November 25, 2008 Author Share Posted November 25, 2008 The whole Internet is not designed to incrementally output content from the web server to the browser. It ties up one of the available server connections for the duration of the task. The best ways to do what you want is to either cause the page to refresh itself perodically or use AJAX to perodically request the information and display it without refreshing the whole page. I thought it might be something like that, unfortunately I haven't gotten around to learning AJAX yet. How are you meaning to refresh the page, through javascript or some function I'm not aware of? Link to comment https://forums.phpfreaks.com/topic/134221-flushing-to-browser/#findComment-698653 Share on other sites More sharing options...
PFMaBiSmAd Posted November 25, 2008 Share Posted November 25, 2008 http://en.wikipedia.org/wiki/Meta_refresh Link to comment https://forums.phpfreaks.com/topic/134221-flushing-to-browser/#findComment-698659 Share on other sites More sharing options...
bluesoul Posted November 25, 2008 Author Share Posted November 25, 2008 Ah, I suppose I'm afraid of losing my place in the loop but I suppose with a $_GET or something it could keep going. Thanks for the advice. Link to comment https://forums.phpfreaks.com/topic/134221-flushing-to-browser/#findComment-698666 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.