How to echo print right now in PHP?

By default, it will not print anything until it completes the entire page.

Is there any function that can clear it right away?

But without calling ob_end_flush() several times, which I don't want.

Hope you guys got me?

+6
php flush
source share
4 answers

If output buffering is enabled, then flushing is the only way to output anything to the browser. If you want to output immediately, then output buffering. If this is not under your control, you can simply call ob_end_flush () in the srart of your script, which will disable output buffering. However, some messages cannot be transmitted, and some cannot (without writing custom echo / print functions)

calling ob_end_flush () will disable and disable the topmost output buffer. To make sure that all output buffers are turned off and flushed, you can easily do this:

 while (@ob_end_flush()); 
+8
source share

This will depend on your web server. A flush call will clear the output of any current buffer, however, as the related page says:

flush () does not affect the client-side buffering scheme of your web server or browser. Thus, you need to call both ob_flush () and flush () to clear the output buffers.

Several servers, especially on Win32, will still buffer the output from your script until it completes before the results are sent to the browser.

Server modules for Apache, such as mod_gzip, can do their own buffering, which will cause flush () to not immediately send data to the client.

+6
source share

You can disable output buffering on your development / testing server. Change the output_buffering parameter in the php.ini configuration file.

+1
source share

ob_end_flush () throws a notification if it is used at the top of the script when there is no buffer. This can be a problem if you plan to set cookies or headers. I found that this did not affect the buffering on my shared server (Rackspace Reseller).

0
source share

All Articles