PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ob_get_clean> <ob_end_flush
Last updated: Fri, 18 Jul 2008

view this page in

ob_flush

(PHP 4 >= 4.2.0, PHP 5)

ob_flush — Flush (send) the output buffer

Description

void ob_flush ( void )

This function will send the contents of the output buffer (if any). If you want to further process the buffer's contents you have to call ob_get_contents() before ob_flush() as the buffer contents are discarded after ob_flush() is called.

This function does not destroy the output buffer like ob_end_flush() does.

Return Values

No value is returned.



ob_get_clean> <ob_end_flush
Last updated: Fri, 18 Jul 2008
 
add a note add a note User Contributed Notes
ob_flush
colnector at@ colnect punto com
08-Jul-2008 04:35
As stated in flush() manual entry, if php compresses the ouput with zlib this function may be ineffective.

A possible option for folders on your server that have scripts which may take a long time to run is to add the following in your relevant .htaccess file:

<FilesMatch "\.(php|html?)$">
php_flag zlib.output_compression off
php_value max_execution_time 3000
php_value max_input_time 3000
</FilesMatch>
kel at no-spam dot newcastleinfotech dot com dot au
05-Jun-2008 09:33
Also note that any data in the buffer will flush at the end of the script, not destroyed, so it is often not necessary to call ob_flush(); for example:

<?php
ob_start
();
echo
'Hello World!'
?>

Will still result in Hello World! being displayed to the browser.
matt at ihaventthefoggiest dot com
22-May-2008 12:25
Just to note, I don't think image output functions (imagejpeg, imagegif etc) are caught by ob. This code:
<?php
ob_start
();
$im = imagecreateturecolor(100,20);
$white = imagecolorallocate($error_im,255,255,255);
$black = imagecolorallocate($error_im,0,0,0);
imagefttext($im,12,0,0,0,$black,'font.ttf','Hello, world!');
imagegif($im);
ob_flush();
?>
will still produce a black on white image saying "Hello, world!"
solidli at gmail dot com
23-May-2007 09:28
Use an '@' sign as "@ob_flush();" to avoid the following message:

Notice: ob_flush(): failed to flush buffer. No buffer to flush. in /etc/www/test.php on line 88
21-Sep-2005 06:37
I was having problems with output buffering which seemed to be active by default on the server, although phpinfo said something else..

In any case I needed to know that when I ran ob_start, it would start at the top level, so I could use ob_flush as it's intended without having to call multiple ob_flush in-script - this is what I did:

<?php

// make sure output buffering is off before we start it
// this will ensure same effect whether or not ob is enabled already
while (ob_get_level()) {
   
ob_end_flush();
}
// start output buffering
if (ob_get_length() === false) {
   
ob_start();
}

?>

Then I could call ob_flush(); followed by flush(); and get the output I wanted, which I didn't if I started the script with just ob_start();

This was on a windows apache 2 server with php 5.0.4 btw.
24-Jun-2005 06:27
You must call them in the correct order.
ob_flush();
flush();
Reynard Hilman
22-Jun-2005 02:29
when using command line php, if somewhere in your script you have ob_start(), you have to call ob_end_flush() first, and then you can call these functions:
flush();
ob_flush();

without calling ob_end_flush first, flush and ob_flush does not have any effect, at least that's what I experienced.
jeremy at e2-media dot co dot nz
25-May-2005 04:09
we had problems with flushing data to the browser. a simple call to ob_flush() or flush() would not work. We found that repeatly calling theses fuctions did work however.

<?
flush
();
ob_flush();
flush();
ob_flush();
flush();
ob_flush();
?>

go figure!
14-Jan-2003 08:23
As far as I can tell the only way to mimic ob_flush()'s behaviour on PHP < 4.2.0 is calling ob_end_flush() followed by ob_start().

ob_get_clean> <ob_end_flush
Last updated: Fri, 18 Jul 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites