Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

<? ob_start("ob_gzhandler"); ?>

3 views
Skip to first unread message

Mike S

unread,
Sep 1, 2010, 5:09:14 AM9/1/10
to
I read an article about using gzip to speed up page downloads, and I was
referred to this page:

http://www.whatsmyip.org/http_compression/phpgzip/

where this code is recommended:

<? ob_start("ob_gzhandler"); ?>

Is there any reason not to use this code, such as a superior choice?

"Álvaro G. Vicario"

unread,
Sep 1, 2010, 7:05:24 AM9/1/10
to

Points to consider about compression, in no particular oder:

- It saves bandwidth and expends memory and CPU.
- It may add a noticeable delay before the browser starts displaying the
page.
- It prevents the server from generating the Content-Length header (and
if you have a download script that generates it, it's likely to break).
- It effectively disables progressive output.
- Short documents may actually take longer to download.
- If you use PHP to generate binary data that's already compressed (such
as pictures) you'll just waste resources.
- Some browsers have known issues with compressed documents.

To sum up, it can be a nice tool (I actually use it in most of my
personal sites) but you need to make sure you understand its drawbacks
so you can make a informed choice.

Also, some web servers already provide compression features and it can
be easier to use that instead of PHP's. For instance, you can compress
CSS or JavaScript without the need of using PHP to serve it.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--

Mike S

unread,
Sep 1, 2010, 6:09:38 PM9/1/10
to

Thanks for your detailed reply. The author of the
whatsmyip.org site commented that,

"The advantages (of mod_deflate) are that you don't have to add more
code to every page. Plus it will compress things like css and JavaScript
and XML too. And "they" say that mod_deflate is slightly faster than
compressing in php."

Do you know of any modern browsers that have an issue wtih mod_deflate,
if I can get the ISPs to enable it?

Thanks,
Mike

Michael Fesser

unread,
Sep 1, 2010, 8:04:19 PM9/1/10
to
.oO(Mike S)

>Thanks for your detailed reply. The author of the
>whatsmyip.org site commented that,
>
>"The advantages (of mod_deflate) are that you don't have to add more
>code to every page. Plus it will compress things like css and JavaScript
>and XML too. And "they" say that mod_deflate is slightly faster than
>compressing in php."
>
>Do you know of any modern browsers that have an issue wtih mod_deflate,
>if I can get the ISPs to enable it?

The only browser I know which had problems with compressed content every
now and then was Netscape 4. I think today it's pretty safe to use it.

Micha

Mike S

unread,
Sep 1, 2010, 8:17:29 PM9/1/10
to
On 9/1/2010 5:04 PM, Michael Fesser wrote:
> .oO(Mike S)
>
<snip>

>> Do you know of any modern browsers that have an issue wtih mod_deflate,
>> if I can get the ISPs to enable it?
>
> The only browser I know which had problems with compressed content every
> now and then was Netscape 4. I think today it's pretty safe to use it.
>
> Micha

Micha,

Netscape 4... I can live with that. <grin>

Thanks,
Mike

Jerry Stuckle

unread,
Sep 1, 2010, 10:45:52 PM9/1/10
to

It's really not a problem for the web server to handle it - but it can
be if your code handles it.

The browser, as part of the header, sends what formats it can accept,
i.e. if it can accept gzipped files, it will say so. The web server can
look at the headers and gzip the files iff the browser accepts it. But
the web server won't if the browser won't accept it.

Your code would gzip the files under all conditions, which can cause a
problem.

And Netscape4 isn't necessarily the only problem - for instance, cURL
may or may not be able to handle it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================

"Álvaro G. Vicario"

unread,
Sep 2, 2010, 2:25:58 AM9/2/10
to
El 02/09/2010 0:09, Mike S escribió/wrote:
> Do you know of any modern browsers that have an issue wtih mod_deflate,
> if I can get the ISPs to enable it?

If you refer to compression in general rather than mod_deflate, well, it
depends on your definition of "modern". I've seem some cases when IE6
would not display styles if the *.css file was compressed (but it was
completely random).

In this sense, I think it is a safe choice if whatever tool you use
obeys the Accept-Encoding header. Both mod_deflate and ob_gzhandler do
if I recall correctly.

Mike S

unread,
Sep 2, 2010, 3:05:23 AM9/2/10
to
On 9/1/2010 11:25 PM, "Álvaro G. Vicario" wrote:
> El 02/09/2010 0:09, Mike S escribió/wrote:
>> Do you know of any modern browsers that have an issue wtih mod_deflate,
>> if I can get the ISPs to enable it?
>
> If you refer to compression in general rather than mod_deflate, well, it
> depends on your definition of "modern". I've seem some cases when IE6
> would not display styles if the *.css file was compressed (but it was
> completely random).
>
> In this sense, I think it is a safe choice if whatever tool you use
> obeys the Accept-Encoding header. Both mod_deflate and ob_gzhandler do
> if I recall correctly.

Interesting, based on what you said I did another search and found this:

http://php.net/manual/en/function.ob-gzhandler.php

ob_gzhandler
(PHP 4 >= 4.0.4, PHP 5)
ob_gzhandler — ob_start callback function to gzip output buffer
Description
string ob_gzhandler ( string $buffer , int $mode )
"ob_gzhandler() is intended to be used as a callback function for
ob_start() to help facilitate sending gz-encoded data to web browsers
that support compressed web pages. Before ob_gzhandler() actually sends
compressed data, it determines what type of content encoding the browser
will accept ("gzip", "deflate" or none at all) and will return its
output accordingly. All browsers are supported since it's up to the
browser to send the correct header saying that it accepts compressed web
pages. If a browser doesn't support compressed pages this function
returns FALSE."

...and further down the page where they display comments:

steve at mrclay dot org
16-Jul-2008 04:31
The Accept-Encoding header can't be trusted in IE5 and unpatched IE6;
there are gzip-related bugs in this browsers. The docs don't mention if
ob_gzhandler knows about these, so you might want to use the function below:

<?php
function isBuggyIe() {
$ua = $_SERVER['HTTP_USER_AGENT'];
// quick escape for non-IEs
if (0 !== strpos($ua, 'Mozilla/4.0 (compatible; MSIE ')
|| false !== strpos($ua, 'Opera')) {
return false;
}
// no regex = faaast
$version = (float)substr($ua, 30);
return (
$version < 6
|| ($version == 6 && false === strpos($ua, 'SV1'))
);
}

// usage:
isBuggyIe() || ob_start("ob_gzhandler");
?>

--------------------------------------------------------------
and this...

http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/

Caveats

As exciting as it may appear, HTTP Compression isn’t all fun and games.
Here’s what to watch out for:

Older browsers: Yes, some browsers still may have trouble with
compressed content (they say they can accept it, but really they can’t).
If your site absolutely must work with Netscape 1.0 on Windows 95, you
may not want to use HTTP Compression. Apache mod_deflate has some rules
to avoid compression for older browsers.
-------------------------------------------------------------

I don't think IE5 or Netscape 1 are used very often, and I would guess
that most IE6 installations are patched by now, so I'll keep using it
and see if I get complaints from users.

Thanks,
Mike

0 new messages