Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP flush() doesn't work with laravel?

Tags:

php

laravel

I'm using Laravel and I need to output data as it happens. When I attempt to load the page outside Laravel, it works just fine. If I use this inside Laravel, it doesn't flush, it waits until the end and prints the results.

view.php

<?php

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

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

    ob_flush();
    flush();
    sleep(1);

}
ob_end_flush();
?>
like image 803
sdot257 Avatar asked Dec 09 '12 19:12

sdot257


2 Answers

Figured it out, I needed to add ob_flush();

like image 105
sdot257 Avatar answered Nov 06 '22 12:11

sdot257


Update, for anyone coming here.

The above solutions didn't work for me. What worked, is adding the

header('X-Accel-Buffering: no');

before any output.

Found it here: https://laracasts.com/discuss/channels/laravel/live-output-in-blade-template-ob-flush

like image 40
Yosef Avatar answered Nov 06 '22 14:11

Yosef