Re: Problems with GZIPped content in some cases?!?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Olaf Greve wrote:

Hi all,

Firstly, I'm new to this list, so I'm hoping I'm not flogging a dead horse with this question, and I also hope I'm not inadvertently breaking any list etiquete in any way...
Should this be the case, I apologise in advance. :P

Alright, with that out of the way, I'll post my actual question:

I find myself with very limited time to fix a bug in my code regarding explicit GZIP compression. The server on which it runs (Debian Linux, PHP 4.1.2) does not have the output handler set to ob_gzhandler, nor does it have the zlib.compression directive set to on.

Now, when using the (shortened for brevity) below code I was given previously for this, I run into the following weird behaviour:
-It works for most people.
-For some people, their browser prompts them that it wants to download an application of type PHP. -For yet some other people, the shown page seems to only contain a lot of garbled (GZIPped, I suppose...) data.

I have previously seen weird things like this happen with GZIP (particularly when enabling it via the php.ini directives AND then trying to do so explicitly with code like the code posted here), but in this case I'm not certain what the exact source of the problem is (I'm guessing something with the headers is off or so)...

Then: this sounds like something that other developers will previously have run into, so I'm hoping someone knows the definitive answer, or at least some good pointers for solving it...

So, if someone has any ideas, can they please let me know (off-list in case the reply is deemed off-topic for this list)?

Thank you all kindly in advance, and with kind regards,
Olaf Greve



<?
ob_start();
ob_implicit_flush(0);

function CheckCanGzip(){
    global $HTTP_ACCEPT_ENCODING;
    global $HTTP_HOST;
    if (headers_sent() || connection_aborted()) return 0;
    if (strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false) return "x-gzip";
    if (strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false) return "gzip";
    return 0;
}

function gzdataout($level=1){ // level = compression level 0-9, 0=none, 9=max

    $Encoding = CheckCanGzip();

    $Content = ob_get_contents();
    ob_end_clean();

    if($Encoding){
        header("Content-Encoding: ".$Encoding);
        echo "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xFF";
        echo substr(gzcompress($Content,$level),2,-4);
    } else {
        echo $Content;
    }
    flush();
    exit();
}
?>
....actual page content....
<?
gzdataout();
?>

This is surely a browser problem.
I have encuntered the same stuff, over and over. by a few people.

I have created the gzips locally and sended it to them.
No problems since then.

Greets
	Barry

--
Smileys rule (cX.x)C --o(^_^o)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux