Размер файла: 1.55Kb
<?php
error_reporting(0);
if($_SERVER['HTTP_ACCEPT_ENCODING']){
$compress = strtolower($_SERVER['HTTP_ACCEPT_ENCODING']);
}
else{
$compress = strtolower($_SERVER['HTTP_TE']);
}
if(substr_count($compress,'deflate'))
{
function compress_output_deflate($output){
return gzdeflate($output, 5);
}
$method = 'deflate';
header('Content-Encoding: deflate');
ob_start('compress_output_deflate');
ob_implicit_flush(0);
}
elseif(substr_count($compress,'gzip'))
{
function compress_output_gzip($output){
return gzencode($output, 5);
}
$method = 'gzip';
header('Content-Encoding: gzip');
ob_start('compress_output_gzip');
ob_implicit_flush(0);
}
elseif(substr_count($compress,'x-gzip'))
{
function compress_output_x_gzip($output){
$size = strlen($output);
$crc = crc32($output);
$output = gzcompress($output, 5);
$output = substr($output, 0, strlen($output) - 4);
return "\x1f\x8b\x08\x00\x00\x00\x00\x00".$output.pack('V',$crc).pack('V',$size);
}
$method = 'x-gzip';
header('Content-Encoding: x-gzip');
ob_start('compress_output_x_gzip');
ob_implicit_flush(0);
}
function info()
{
global $method;
$contents = ob_get_contents();
$in = strlen($contents);
switch($method){
default:
print 'выкл';
break;
case 'deflate':
$out = strlen(gzdeflate($contents, 5));
print round(100-(100/($in/$out)),1).' %';
break;
case 'gzip':
$out = strlen(gzencode($contents, 5));
print round(100-(100/($in/$out)),1).' %';
break;
case 'x-gzip':
$out = strlen(gzcompress($contents, 5));
print round(100-(100/($in/$out)),1).' %';
break;
}
return;
}
?>