Max
Max

Reputation: 499

How do I output contents in browser while the script is running?

I'm trying to output echo's contents while my script is running. Having read a few tutorials, I do the following:

ob_start();

echo "bla bla bla<br>";
ob_flush();
flush();
sleep(5);
echo "bla bla bla<br>";

ob_end_flush();

But It doesn't solve the problem. I still get all output after the script finished its work. Output_buffering is set to Off.

ob_implicit_flush() also doesn't help.

I use PhP 5.5 and Safari to display contents.

Upvotes: 0

Views: 67

Answers (1)

ElectroNis
ElectroNis

Reputation: 111

If i understend You well this is what you asked for.

if (ob_get_level() == 0) ob_start();

for ($i = 0; $i<10; $i++){

        echo "<br> Line to show.";
        echo str_pad('',4096)."\n";    

        ob_flush();
        flush();
        sleep(2);
}

echo "Done.";

ob_end_flush();

Upvotes: 2

Related Questions