Gzip compression

From: Date: Fri, 02 Feb 2001 15:14:08 +0000
Subject: Gzip compression
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-37846@lists.php.net to get a copy of this message
I'm looking at implementing Gzip compression and output buffering. I think I have it working, but for some reason, the page isn't displayed for 8-10 seconds. It seems that the compressed page is sent immediately, but the browser hangs on to it for some reason. http://www.dvanhorn.org/Test/Index.php Compressed http://www.dvanhorn.org/Test/Index2.php Not compressed Here's the top level page code: <? ob_start(); include('gzdoc.php'); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="description" content="Web Page Status"> <meta name="GENERATOR" content="Notepad"> <? include("../headmeta.inc")?> <title>Current status.</title> <? include ("Header.inc")?> </head> <body> <BODY BACKGROUND="../../Graphics/b_m.gif"> <? include("Index.inc") ?> <? include("../footer.inc") ?> <? include("../do_webtrends.php") ?> </body> </html> <? gzdocout(); ?> There are NO chars before, or after, the PHP flags. Here is the contents of gzdoc.php. <? ob_start(); flush(); $debug="1"; $Level="4"; function CheckCanGzip(){
    $ret = "0";
    global $HTTP_ENCODING;
    if (headers_sent() || connection_timeout() || connection_aborted()) $ret = "0";
    if (strpos($HTTP_ENCODING,'x-gzip') != false) $ret = "x-gzip";
    if (strpos($HTTP_ENCODING,'gzip'  ) != false) $ret = "gzip";
    return $ret;
    }
function GzDocOut($Level,$debug){
    $ENCODING = CheckCanGzip();
    if ($ENCODING){
        print "\n<!-- Use compress $ENCODING -->\n";
        $Contents = ob_get_contents();
        ob_end_clean();
        $Size = strlen($Contents);
        $Crc = crc32($Contents);
        $CContents = gzcompress($Contents,$level);
        $CContents = substr($CContents, 0, strlen($CContents) - 4);
        Header('Content-Encoding: '.$ENCODING);
        Header('Content-Length: ' . strlen($CContents));
        Header('Content-Length: ' . strlen(ob_get_length));
        echo $CContents;
        echo pack('V',$Crc) . pack('V',$Size);
        exit;
    }else{
        ob_end_flush();
        exit;
    }
} ?> -- Where's dave? http://www.findu.com/cgi-bin/find.cgi?kc6ete-9

« previous php.general (#37846) next »