<?php
/*
gzip.lib.php
Version 1.0 Jason M. Knight, August 2009
Uses a proper exit handler to provide automation of gzip compression of our
PHP output with little if any headaches.
ASSUMES:
CONTENT_ENCODING contains either 'x-gzip' or 'gzip' based on the value in
HTTP_ACCEPT_ENCODING. See "defines.php" to see how this is set.
If STRIP_WHITESPACE is defined whitespace between tags or at the start of
lines will be stripped, as will comments. Whitespace between a tag and
CDATA or between attributes will be left alone.
*/
ob_start();
ob_implicit_flush(0);
register_shutdown_function(function() {
header('Content-Encoding: ' . CONTENT_ENCODING);
$contents = ob_get_contents();
if (defined('STRIP_WHITESPACE')) $contents = preg_replace(
['#<!--.*?-->#s', '#>\s+<#', '#\n\s+<#'],
['', '><', '<'],
$data
);
ob_end_clean();
echo "\x1f\x8b\x08\x00\x00\x00\x00\x00",
substr(gzcompress($contents, 6), 0, -4);
});