PHP Classes

Selective Compression

Recommend this page to a friend!

      PHP Classes blog  >  Responsive AJAX appli...  >  All threads  >  Selective Compression  >  (Un) Subscribe thread alerts  
Subject:Selective Compression
Summary:Have you explored doing selective compression on your output?
Messages:4
Author:Gene Comer
Date:2006-09-27 14:20:55
Update:2007-03-10 07:50:21
 

  1. Selective Compression   Reply   Report abuse  
Picture of Gene Comer Gene Comer - 2006-09-27 16:15:34
Would it be possible to compress each response individually using something like:

ob_start("ob_gzhandler");
// response output here
ob_end_flush();

-=or=-

ini_set('zlib.output_compression', 'On');
// response output here
ini_set('zlib.output_compression', 'Off');
// probably need a flush() here

Most responses I can see this not being an issue, but if you are returning search results or something similar with large amounts of data....

  2. Re: Selective Compression   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-09-27 16:54:42 - In reply to message 1 from Gene Comer
Yes, you are right, I forgot to mention that alternative.

I have discarded ob_gzhandler in the past because the PHP manual is wrong where it states that all browsers that send Accept-Encoding: gzip really support gzip compression correctly. The reality is different though, as documented in the mod_gzip page.

I ended up using mod_gzip also because it is the fastest way to add compression to your pages. With simple configuration rules, you can exclude all problematic cases without having to touch your PHP code.

Additionally, mod_gzip can compress static HTML pages and pages generated by scripts in other languages besides PHP.

  3. Re: Selective Compression   Reply   Report abuse  
Picture of robertsnoog robertsnoog - 2007-03-10 07:22:09 - In reply to message 1 from Gene Comer
a good gzip file it works on every browser except IE7

IE7 have problem with ob_start('ob_gzhandler');

Reproduce code:

$name = 'test.sql.gz';
header("Pragma: no-cache");
header("Content-Type: application/x-gzip; name=\"$name\"");
header("Content-disposition: attachment; filename=$name");

ob_start('ob_gzhandler');
echo "test";

  4. Re: Selective Compression   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-03-10 07:50:21 - In reply to message 3 from robertsnoog
The problem mentioned in the article is more with old browsers.

Your problem may be due to those headers that you add to the response.

There are certain versions of Windows and Internet Explorer that give problems when open external programs to handle files being downloaded. If the user saves the file to disk first, that avoids the problem.