PHP Doku:: Leert (sendet) den Ausgabepuffer - function.ob-flush.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDas Verhalten von PHP beeinflussenAusgabepufferungOutput-Control-Funktionenob_flush

Ein Service von Reinhard Neidl - Webprogrammierung.

Output-Control-Funktionen

<<ob_end_flush

ob_get_clean>>

ob_flush

(PHP 4 >= 4.2.0, PHP 5)

ob_flush Leert (sendet) den Ausgabepuffer

Beschreibung

void ob_flush ( void )

Diese Funktion sendet den aktuellen Inhalt des Ausgabepuffers (falls vorhanden). Wenn sie die Pufferinhalte mit ob_get_contents() weiterverarbeiten wollen so müssen sie dies vor Aufruf von ob_flush() tun da diese sonst nicht mehr vorhanden sind.

Anders als bei ob_end_flush() bleibt der Ausgabepuffer erhalten.

Rückgabewerte

Es wird kein Wert zurückgegeben.

Siehe auch

  • ob_get_contents() - Gibt den Inhalt des Ausgabe-Puffers zurück
  • ob_clean() - Löscht den Ausgabepuffer
  • ob_end_flush() - Leert (schickt/sendet) den Ausgabe-Puffer und deaktiviert die Ausgabe-Pufferung
  • ob_end_clean() - Löscht den Ausgabe-Puffer und deaktiviert die Ausgabe-Pufferung


13 BenutzerBeiträge:
- Beiträge aktualisieren...
riimeik
17.10.2010 22:44
If you're still not getting the buffer work correctly then try to clean all the others before starting your own (and even if PHP tells you that there are no buffers active):

while(@ob_end_clean());
sebastian at jcompare dot com
27.04.2009 4:05
For some reason, calling just flush or ob_flush or even both together did not get my output buffers flushed, and calling ob_end_flush by itself didn't work either but calling them all worked well. Here is my new output flushing function.

<?php
function flush_buffers(){
   
ob_end_flush();
   
ob_flush();
   
flush();
   
ob_start();
}
?>

Enjoy
Jens
30.10.2008 4:01
If you call ob_flush() and flush() and still dont get the buffer flushed it might be because some antivirus software (Panda in this case) holds the buffer until the page has finished loaded before sending it to the browser.
Lucas
28.08.2008 0:13
I just had some problems with flush() and ob_flush(). What I did to resolve this problem took me some time to figure out so I'd like to share what I came up with.

The main problem is the php setting "output_buffering" which can be set too large and will prevent your text from outputting. To change this value you can either set it in php.ini or you can add the line

php_value output_buffering "0"

to your .htaccess file. It will not work with ini_set() since it is PHP_INI_PERDIR.

Next thing is to begin with ob_start();
Then you need
ob_flush();
flush();
before any echo or print.

Your code might look like this:

<?php
ob_start
();

for(
$i=0;$i<70;$i++)
{
    echo
'printing...<br />';
   
ob_flush();
   
flush();

   
usleep(300000);
}

?>

Hope this helps anyone with the same problems.
colnector at@ colnect punto com
8.07.2008 13: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
6.06.2008 6: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.05.2008 21: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.05.2007 18: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

22.09.2005 3: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.06.2005 15:27
You must call them in the correct order.
ob_flush();
flush();
Reynard Hilman
22.06.2005 23: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
26.05.2005 1: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.01.2003 17: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().



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)