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();
?>
Figured it out, I needed to add ob_flush();
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With