Jump to content

Flushing to browser


bluesoul

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.