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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.