> Dude, your web server will compute Content-length for you!
I've noticed that Apache 1.3 doesn't do that.
However, if you’re running Apache 2.2 (and maybe 2.0, haven't experienced that yet) you don't need to worry about Content-Length.
ob_get_length
(PHP 4 >= 4.0.2, PHP 5)
ob_get_length — Return the length of the output buffer
Beschreibung
int ob_get_length
( void
)
This will return the length of the contents in the output buffer.
Rückgabewerte
Returns the length of the output buffer contents or FALSE if no
buffering is active.
Beispiele
Beispiel #1 A simple ob_get_length() example
<?php
ob_start();
echo "Hello ";
$len1 = ob_get_length();
echo "World";
$len2 = ob_get_length();
ob_end_clean();
echo $len1 . ", ." . $len2;
?>
Das oben gezeigte Beispiel erzeugt folgende Ausgabe:
6, 11
Siehe auch
- ob_start() - Ausgabepufferung aktivieren
- ob_get_contents() - Gibt den Inhalt des Ausgabe-Puffers zurück
ob_get_length
Sinured
11-Jul-2007 12:25
11-Jul-2007 12:25
18-Jan-2007 10:49
Dude, your web server will compute Content-length for you!
rush at logic dot cz
02-Dec-2005 11:02
02-Dec-2005 11: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 08:56
15-Oct-2005 08: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
29-Jun-2001 10:58
29-Jun-2001 10: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();
?>