PHP Doku:: Anzahl der aktiven Ausgabepuffer - function.ob-get-level.html

Verlauf / Chronik / History: (50) anzeigen

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

Ein Service von Reinhard Neidl - Webprogrammierung.

Output-Control-Funktionen

<<ob_get_length

ob_get_status>>

ob_get_level

(PHP 4 >= 4.2.0, PHP 5)

ob_get_level Anzahl der aktiven Ausgabepuffer

Beschreibung

int ob_get_level ( void )

ob_get_level() liefert die Anzahl der zur Zeit gleichzeitig (übereinanderliegend) aktiven Ausgabepuffer oder 0 wenn keine Ausgabepufferung genutzt wird.

Rückgabewerte

Gibt die Anzahle der aktiven Ausgabepuffer zurück. Wenn keine Ausgabepufferung aktiv ist wird 0 zurückgegeben.

Siehe auch


3 BenutzerBeiträge:
- Beiträge aktualisieren...

18.05.2005 17:45
Sometimes, ob_get_level() may be off by 1 because at the start of the script, it will return 1 even if ob_start() has never been called (and clearing the output buffer via ob_end_clean() and the like can be done without error).  As a result, the first ob_start() will have an ob_get_level() of 2, the second will be 3, and so on.

I'm not sure if this is a PHP 5 thing or [if it's related to when a] server is set to gzip all html documents.

Also, up until at least PHP 5.0.4 (current version), ob_get_level() will always return 0 inside a destructor.  This happens because the garbage collection for output buffers has already done before the destructor is called.  If you want to do something with the output buffer from within an object before the script exits, using a callback function with ob_start() is the way to go.
bonzini at gnu dot org
7.07.2004 18:03
Even under older PHP, you can decide if output buffering is active (i.e. ob_get_level() > 0) using

   <?php $ob_active = ob_get_length () !== FALSE ?>

Paolo
tit dot petric at nospam dot telemach dot net
22.06.2002 21:01
in case you wanted to use a function to use for deleting all buffered output (to clearly display errors), you have it below

this eliminates the need for ob_end_clean_all() in php. good code :)

<?php
function condor_error($errno, $errstr, $errfile, $errline)
{
       
$errors = array(E_USER_ERROR, E_ERROR, E_PARSE);
        if (
in_array($errno,$errors)) {
                while (
ob_get_level()) {
                       
ob_end_clean();
                }
                echo
"<B>FATAL</B> [".$errno."] ".$errstr."<br>\n";
                echo
"Fatal error at line ".$errline." of file ".$errfile;
                echo
", PHP ".PHP_VERSION." (".PHP_OS.")<br>\n";
                echo
"Aborting...<br><br>\n\n";
                exit;
        }
}

set_error_handler("condor_error");
?>



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",...)