Jump to content

how to echo output in real time, (before script finishes).


daydreamer

Recommended Posts

 

How do I output to the browser before the script finishes executing?

 

For example, the code below will output all 100 $outputs at once, how do I make it so it will output as soon as that section of code is read/processed?

 

<?php
for ($i = 0; $i <= 100; $i++) {
   sleep(3);//I have some code which takes about 3 seconds to execute
   echo $output;
}
?>

 

Thanks.

Link to comment
Share on other sites

Getting this to work is dependent on web server settings, php settings, and browser type and browser settings. While you might get it to work on your local development system or a dedicated server, as soon as you try it on a server that is not fully under your control, it has a chance of not working and you won't be able to get it to work because you won't have the ability to change the server and php settings that affect it.

 

Web servers and browsers are not designed to have the output from one http request be incrementally output and have it rendered in the browser in real time. To get this to work for all web server/php configurations and settings you must make a http request for each piece of output by either having the browser continually refresh the page or use AJAX.

Link to comment
Share on other sites

If the output from an echo is not being sent and rendered by the browser, echoing the content of the output buffer is not going to bypass all the buffering, compression, and minimum length content requirements that the web server, php, and the browser are imposing on the content either.

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.