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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 25, 2008 Share Posted November 25, 2008 http://en.wikipedia.org/wiki/Meta_refresh Quote Link to comment 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. Quote Link to comment 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.