Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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?


El 01/09/2010 11:09, Mike S escribió/wrote:
Quoted text here. Click to load it

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
- 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


On 9/1/2010 4:05 AM, "Álvaro G. Vicario" wrote:
Quoted text here. Click to load it

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?



.oO(Mike S)

Quoted text here. Click to load 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.



On 9/1/2010 5:04 PM, Michael Fesser wrote:
Quoted text here. Click to load it
Quoted text here. Click to load it


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



On 9/1/2010 8:17 PM, Mike S wrote:
Quoted text here. Click to load it

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

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.


El 02/09/2010 0:09, Mike S escribió/wrote:
Quoted text here. Click to load 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.

-- 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


On 9/1/2010 11:25 PM, "Álvaro G. Vicario" wrote:
Quoted text here. Click to load it

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


(PHP 4 >= 4.0.4, PHP 5)
ob_gzhandler — ob_start callback function to gzip output buffer
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:

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 /


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.


Site Timeline