Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1

I'm not sure my last message went through,

I usually compress my php data with gz_handler like that:

<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>

when starting a session.

It doesn't seem to work with couch.

Is there another way?

Hi Paolo,

Couch internally uses ob_start and ob_end rather extensively. Using ob_start("ob_gzhandler") sets the ob_gzhandler function to handle the buffered output which will interfere with the working of Couch.

However that does not mean that one cannot use zip compression with sites running on Couch.
We can use the alternative 'zlib.output_compression' method (in fact PHP manual states that this method is preferred over ob_gzhandler().).

There are three ways (in order of preference) of directing the web server to use this compression -

1. Via php.ini
It requires setting the following directive (if not already done by your hosting provider) in php.ini
Code: Select all
zlib.output_compression = on
zlib.output_compression_level = 6

2. Via .htaccess
If php.ini is off limits, we can alternatively try setting the following in the .htaccess file of your site's root folder (not couch folder)
Code: Select all
php_flag zlib.output_compression on

3. Via PHP
Finally, as the last resort, try placing the following statements in Couch's config.php
Code: Select all
ini_set( 'zlib.output_compression', 'On' );
ini_set( 'zlib.output_compression_level', '6' );

This way the server automatically checks for browsers that accept gzipped contents and does so transparently.

To verify that the server is indeed dishing out gzipped contents, you can use the resources listed here: ... n-website/

Hope this helps.

I don't have access to php.ini, and the php solution didn't work,
and the code for .htaccess

php_flag zlib.output_compression On
created an error

but now it's compressing with

SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png|gif)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary

It seems to work pretty well so far,
is it possible to include it in the writing of gen_htaccess.php for the next time I have to run it?
So I don't have to rewrite it down each time (not that it's that often though…)

I know that this post has passed, but thought I would offer an alternative, and neater solution to compression via .htaccess.

Code: Select all
<FilesMatch "\.(php|html|txt|css|js|pl)$">
SetOutputFilter DEFLATE

Adding the above to your .htaccess file will enable compression of your site. This can be verified here:
4 posts Page 1 of 1

Who is online

In total there are 5 users online :: 0 registered, 0 hidden and 5 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 5 guests