Home » » ob_get_level

ob_get_level

Written By 1 on Tuesday, October 2, 2012 | 9:13 AM

int ob_get_level ( void )

Return the nesting level of the output buffering mechanism

Returns the nesting level of the output buffering mechanism.


For users confused about getting "1" as a return value from ob_get_level at the beginning of a script: this likely means the PHP ini directive "output_buffering" is not set to off / 0. PHP automatically starts output buffering for all your scripts if this directive is not off (which acts as if you called ob_start on the first line of your script).



If your scripts may end up on any server and you don't want end-users to have to configure their INI, you can use the following at the start of your script to stop output buffering if it's already started:

<?php

if (ob_get_level()) ob_end_clean();

?>



Alternatively, you can use the opposite if you always want to have an output buffer at the start of your script:

<?php

if (!ob_get_level()) ob_start();

?>


0 Comment:

Post a Comment