What a co-incidence, I've just created a similar (though far simpler)
version of this exact plugin and am in the process of testing it on my
sites. If you're interested this is all I did:
---
<?php
class GzCompress extends Plugin
{
public function info()
{
return array (
'name' => 'GzCompress',
'url' => 'http://habariproject.org/',
'author' => 'The Habari Community',
'authorurl' => 'http://habariproject.org/',
'version' => '0.1',
'description' => 'Send gzip compressed data to
browsers that support it.',
'license' => 'Apache License 2.0',
);
}
/**
* Force a low priority to ensure we're the last thing run before
outputting
*/
public function set_priorities()
{
return array( 'filter_final_output' => 100 );
}
public function filter_final_output( $buffer )
{
$HTTP_ACCEPT_ENCODING = $_SERVER["HTTP_ACCEPT_ENCODING"];
if ( headers_sent() )
$encoding = false;
else if ( strpos( $HTTP_ACCEPT_ENCODING, 'x-gzip' ) !== false )
$encoding = 'x-gzip';
else if( strpos( $HTTP_ACCEPT_ENCODING, 'gzip' ) !== false )
$encoding = 'gzip';
else
$encoding = false;
if ( $encoding ) {
$length = strlen( $buffer );
if ( $length > 2048 ) { // Only compress content
greater than 2KB
header( 'Content-Encoding: '.$encoding );
print( "\x1f\x8b\x08\x00\x00\x00\x00\x00" );
$buffer = gzcompress( $buffer, 9 );
$buffer = substr( $buffer, 0, $length );
}
}
return $buffer;
}
}
?>
---
So far my testing has been good.
I've not bothered with bzip or deflate compression as bzip tends to be
too CPU intensive for very little gain and most browsers that support
deflate support gzip.
On Tue, Apr 6, 2010 at 5:01 PM, Da:Sourcerer <[email protected]> wrote:
> Hello there,
>
> I've finished a beta of my first plugin for Habari and am looking for
> feedback:
> <http://dasourcerer.net/user/files/http-compression-0.6-1.0-
> beta.tar.bz2>
>
> The plugin adds HTTP compression abilities to Habari, which can help
> to keep traffic costs lower and improve loading
> times on the client side. In an effort to be polite to the client, the
> plugin adds a Content-Length header as well.
>
> Have fun,
> Da:Sourcerer
>
> --
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/habari-dev
>
> To unsubscribe, reply using "remove me" as the subject.
>
--
Colin Seymour
Blog: http://colinseymour.co.uk
Tech Stuff: http://www.lildude.co.uk
Barefoot Running: http://barefootrunner.co.uk
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at http://groups.google.com/group/habari-dev