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

search for in the

ob_get_status> <ob_get_length
Last updated: Fri, 10 Oct 2008

view this page in

ob_get_level

(PHP 4 >= 4.2.0, PHP 5)

ob_get_levelReturn the nesting level of the output buffering mechanism

Opis

int ob_get_level ( void )

Returns the nesting level of the output buffering mechanism.

Zwracane wartości

Returns the level of nested output buffering handlers or zero if output buffering is not active.



ob_get_status> <ob_get_length
Last updated: Fri, 10 Oct 2008
 
add a note add a note User Contributed Notes
ob_get_level
dustymugs
19-Jun-2008 08:53
This is a note in response to the post by Anonymous on 18-May-2005 08:45.

I do not believe that the number is off by one.  On my servers running apache 2.0.59 and php 5.2.4, I too noticed that output buffering was always on though I know I did not specify it.  It turns out that if you use php.ini-recommended for php.ini, "output_buffering" is set to 4096 and thus enabled.  If you use php.ini-dist though, "output_buffering" is turned off.  I guess I never noticed it until now.

From what I can tell, having deflate enabled in apache2 will not affect the count returned by ob_get_level.
Anonymous
23-Dec-2007 01:42
Re: condor_error

I think if you want to supress error messages and the whole page you could just go

<?php
ob_start
();
function
error_handler( ..... ){
   
ob_get_clean();
   
// possibly echo the message here
}
set_error_handler('error_handler');
?>

and optionally output the error. if it's fatal the last output will be sent.
18-May-2005 05: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 possibly because our 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
07-Jul-2004 06:03
Even under older PHP, you can decide if output buffering is active (i.e. ob_get_level() > 0) using

   $ob_active = ob_get_length () !== FALSE

Paolo
tit dot petric at nospam dot telemach dot net
22-Jun-2002 09:01
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");

in case you wanted to use a function to use for deleting all buffered output (to clearly display errors), you have it above

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

ob_get_status> <ob_get_length
Last updated: Fri, 10 Oct 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites