Show results while script is still executing

Solution 1:

You can use output buffering like this:

ob_start();

echo('doing something...');

// send to browser
ob_flush();

// ... do long running stuff
echo('still going...');

ob_flush();

echo('done.');
ob_end_flush(); 

Solution 2:

This one worked for me: (source)

function output($str) {
    echo $str;
    ob_end_flush();
    ob_flush();
    flush();
    ob_start();
}

Solution 3:

You can do that with output buffering. Turn on output buffering at the top of your script with ob_start(). That makes PHP to send no output to the browser. Instead its stored internally. Flush your output at any time with ob_flush(), and the content will be sent to the browser.
But keep in mind that output buffering is influenced by many other factors. I think some versions of IIS will wait until the script is finished, ignoring output buffering. And some Antivirus software on client side (Was it Panda?) might wait until the page is fully loaded before passing it through to the browser.

Solution 4:

I had to put both ob-flush and flush as shown in this example:

for($i=10; $i > 0; $i--)
{
    echo "$i ...";
    flush();
    ob_flush();
    sleep(1);
}