tags:

views:

285

answers:

4

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?

+6  A: 

It will depend on your webserver. Calling flush will flush the output of whatever current buffer is open, however, as it says on the linked page:

flush() has no effect on the buffering scheme of your web server or the browser on the client side. Thus you need to call both ob_flush() and flush() to flush the output buffers.

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

Server modules for Apache like mod_gzip may do buffering of their own that will cause flush() to not result in data being sent immediately to the client.

Aistina
+6  A: 

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());
Pim Jager
+1 You would be correct
karim79
Do you mean that by calling ob_end_flush() once,the subsequent echo/print functions will output right away?
Shore
@Shore, Yes that is what I mean. calling ob_end_flush() turns of the top most output buffer.
Pim Jager
+1  A: 

You could turn off output-buffering on your development/test-server. Change the output_buffering variable in your php.ini configuration file.

PatrikAkerstrand
A: 

ob_end_flush() will throw a notice if it is used at the top of the script when there is no buffer to flush. This may be an issue if you are planning to set cookies or headers. I found it did not affect the buffering on my shared server (Rackspace Reseller).

Ray_Paseur