13.8 Other OB functions: ob_get_length(), ob_get_level(), and ob_list_handlers()This is NOT the latest copy of this book; click here for the latest version.
int ob_get_length ( void )
int ob_get_level ( void )
array ob_list_handlers ( void )
There are three other output buffering functions that are of interest: ob_get_length(), ob_get_level(), and ob_list_handlers(). Both take no parameters and return a number - for ob_get_length(), the return value is the number of bytes held in the buffer, and for ob_get_level() it is the "nest count". Ob_get_level() returns 0 if you are not within an output buffer, 1 if you have got one open, 2 if you have got two, etc.
Using ob_get_level() it is possible to recursively close and flush/clean all open buffers if you have an error, and ob_get_length() is helpful if you want to send a custom HTTP Content-Length header - although that is for advanced users only!
Finally, the ob_list_handlers() function takes no parameters and returns an array of any output handlers currently in effect. If output buffering is turned on, you should get back an array containing "default output handler", if you're using gzip to compress your buffer you should get "ob_gzhandler", and if you've used URL rewriting you should get "URL-Rewriter".
|
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.
My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!
|