note 34556 added to function.gzcompress
| From: | dwales at rack1 dot php dot net | Date: | Wed, 30 Jul 2003 17:48:21 +0000 |
| Subject: | note 34556 added to function.gzcompress | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-53025@lists.php.net to get a copy of this message | ||
I find this works well, save the snip below in your php/ directory then edit your prepend.php file
and add a require statement that requires the compression.php file below. Once complete watch (tail
-f) your php error log to see the results of compression in action.
<?php
// Gzip encode the contents of the output buffer.
function compress_output_option($output)
{
// Compress the data into a new var.
$compressed_out = gzencode($output);
// Don't compress any pages less than 1000 bytes
// as it's not worth the overhead at either side.
if(strlen($output) >= 1000)
{
error_log('compression.php Gzipd Output'."\n"
.'Before compression size '
.strlen($output).' bytes'."\n"
.' After compression size '
.strlen($compressed_out).' bytes');
// Tell the browser the content is compressed with gzip
header("Content-Encoding: gzip");
return $compressed_out;
}
else
{
// No compression
error_log('compression.php Standard Output.');
return $output;
}
}
// Check if the browser supports gzip encoding, HTTP_ACCEPT_ENCODING
if (strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip'))
{
// Start output buffering, and register compress_output() (see
// below)
ob_start("compress_output_option");
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.gzcompress.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34556
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34556&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34556&report=yes