Ok, I've done a bit of reading up on some of the zlib functions and have a rudimentary understanding of the whole thing. I decided to make a quick gzip function that compresses output if the current browser supports it.
Not sure what I'm doing wrong here as I seem to be getting nothing but Japanese gibberish instead of what I want to output:
<?php
ob_start("ob_gzhandler");
function doGzip($encoding, $level = 9) {
if (strpos($encoding, 'gzip') === false) {
return;
}
strpos($encoding, 'x-gzip') === false ? $encode = 'gzip' : $encode = 'x-gzip';
$out = ob_get_contents();
@Header('Content-Encoding: ' . $encoding);
@Header('Vary: Accept-Encoding');
@Header('Content-Length: ' . strlen($out));
$out = "\x1f\x8b\x08\x00\x00\x00\x00\x00" . substr(gzcompress($out,$level), 0, -4) . pack('V', crc32($out)) . pack('V', strlen($out));
ob_end_clean();
echo $out;
}
echo "Hey, look at me! I'm not working!";
doGzip($_SERVER['HTTP_ACCEPT_ENCODING']);
?>
Any help? 😕