Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make echo print out right away in PHP?

Tags:

php

flush

By default it will not print out anything until the whole page has finished executing.

Is there any function that can make it flush out right away?

But not by calling ob_end_flush() multiple times, which is not what I want.

Hope you guys got me?

like image 498
omg Avatar asked Jun 10 '09 19:06

omg


1 Answers

If output buffering is on, then flushing it is the only way to output anything to the browser. If you want to output right away then turn of output buffering. If that is not in your control you can just call ob_end_flush() at the srart of your script which will turn the output buffering off. There is no way however to let some messages pass, and some not (without writing custom echo/print functions)

calling ob_end_flush() will flush and turn off the top most output buffer. To make sure all output buffers are turned off and flushes you can easily do this:

while (@ob_end_flush());
like image 163
Pim Jager Avatar answered Oct 03 '22 10:10

Pim Jager