ob_get_length

(PHP 4 >= 4.0.2, PHP 5)

ob_get_length --  Return the length of the output buffer

Description

int ob_get_length ( void )

This will return the length of the contents in the output buffer or FALSE, if output buffering isn't active.

See also ob_start() and ob_get_contents().


add a note add a note User Contributed Notes
rush at logic dot cz
02-Dec-2005 06:02
There is a work-around for the situation you need to get length of the gz-ed buffer.

ob_start();
ob_start('ob_gzhandler');

  ... output the page content...

ob_end_flush();  // The ob_gzhandler one

header('Content-Length: '.ob_get_length());

ob_end_flush();  // The main one

more info at http://www.edginet.org/techie/website/http.html
prophp at gmail dot com
15-Oct-2005 02:56
It's interesting how ob_start("ob_gzhandler"); or ob_gzhandler(); affect this function. The returned size is the buffer uncompressed size; therefore something like strlen(ob_get_contents()); just (hopefully) faster. However in order to obtain the compressed buffer size; there seem to be no function around.

Calin
webmaster at crescentart dot com
30-Jun-2001 04:58
Here is an easy way to get the header Content-Lenght.
<?
ob_start
();
?>

Put HTML tags.

<?
$size
=ob_get_length();
header("Content-Length: $size");
ob_end_flush();
?>