Revision [6606]

This is an old revision of DetectingZlibOutputCompression made by JavaWoman on 2005-03-08 17:26:09.

 

How to detect automatically if zlib.output_compression is set?

Wikka has a problem when zlib.output_compression is set. This is a simple technique to make wikka compatible and requires no action from administrator when the server environment change :
 ob_start();
 ob_start('ob_gzhandler');
 $data = ob_get_contents();
 if (strlen($data) != 0)
 {
  $_SERVER['HTTP_ACCEPT_ENCODING'] = "none";
 }
 else ob_end_clean();
 ob_end_clean();


A more interesting usage is to change the ./wikka.php like this :
1) Remove the following lines from the bottom :
if (strstr ($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') && ($wakka->config['allow_gzip']))
{
   // Tell the browser the content is compressed with gzip
    header ("Content-Encoding: gzip");
    $page_output = gzencode($content, 9);
    $page_length = strlen($page_output);
 header('Content-Length: '.$page_length);
} else {
    $page_output = $content;
}


2) Replace the ob_start() at the top of ./wikka.php by
ob_start(); //so that eventual error message from the next ob_start won't be printed.
ob_start('ob_gzhandler'); //test zlib.compression
$data = ob_get_contents();
$ob_gzhandler_is_ok = (strlen($data) == 0);
ob_end_clean();
ob_end_clean(); //close all possible opened buffers
$ob_gzhandler_is_ok ? ob_start('ob_gzhandler') : ob_start(); //and reopen buffer.



Question:
The PHP manual suggests the using of ZLib library is preferable to using ob_gzhandler. Now, I have no idea why one is preferable to the other (speed?, but then how widespread is zlib module in PHP installs for e.g.?), so I ask if anyone knows why. If a user has zlib installed, then another alternative is to use .htaccess:

<FilesMatch "\.(php|html?)$">
php_value zlib.output_compression 4096
</FilesMatch>


Also - what is the bug you are fixing here - any is it specific to Wikka, or a general bug? Is is browser dependant? I've used zlib.output_compression with wakka for ages without a problem. Thanks for any info! --IanAndolina


Category
WikkaDevelopment
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki