Revision [6583]
This is an old revision of DetectingZlibOutputCompressionFR made by DotMG on 2005-03-08 08:24:59.
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();
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;
}
{
// 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.
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.