Saving bandwidth with DokuWiki

I recently installed DokuWiki on NearlyFreeSpeech; while I love DokuWiki’s features, I quickly noticed that I was being charged for more bandwidth than seemed necessary for the few pages I was viewing and editing.

A quick check of access logs revealed two things. First, DokuWiki does not compress its output using gzip. Second, it does not send appropriate cache control headers to allow essentially static data (e.g. style sheets) to be cached.

Google reveals that it’s easy to actually compress output from PHP. For example, Jan-Piet Mens added one line to doku.php to turn on gzip output compression. I borrowed a snippet from WordPress’s gzip_compression function and added it to inc/init.php (after the init session code):

// Hack: enable gzip output compression -ES
if ( extension_loaded('zlib') ) {
  ob_start('ob_gzhandler');
}

This has the benefit of affecting any file that generates output, including CSS and JS files. (DokuWiki recently introduced its own bizarre CSS/JS compression scheme that breaks Monobook for DokuWiki; gzip compression seems simpler and less error prone.)

I also observed that my browser was repeatedly requesting lib/exe/css.php and lib/exe/js.php; it turns out that others have raised this issue in just the past few weeks. On 10 April 2006, a set of patches was committed that properly generates ETags and Last-modified headers and allows the resulting output to be cached without checking for at most one hour. I manually applied these patches (with this helper patch); where I used to transfer 11k worth of CSS and 70k of JS for each page view, now I send about 2k of CSS and 17k of JS once an hour. My pages load quicker too!

6 Comments

  1. joaquin
    Posted 18 June 2006 at 7:31 pm | Permalink

    Hi. Thanks for this tip… I have a rather random question about installing Dokuwiki on MAMP, maybe you or someone you know might help.

    If you feel inclined to hear my question, please email me. Thanks.

  2. Posted 19 June 2006 at 6:02 pm | Permalink

    Thanks for stopping by. I’m afraid I don’t know what MAMP is; is that like LAMP? You’ll probably find more helpful advice on the DokuWiki wiki! Good luck!

  3. Posted 31 August 2006 at 5:52 pm | Permalink

    Nice tip which saved me quite some time! :-)

    I’m also running Dokuwiki on NFSN. The speed was somewhat disappointing, but your gzip output compression trick surely helps. The homepage of http://www.paldap.org/ just went from 153kb to 64kb.

    Now to do something about the rest of the performance issues. For that, I guess I’ll have to do some profiling, although, from experience with personal PHP projects, I’d say the problem is probably related to the reimplementation of too much web server functionality in lib/exe/fetch.php, for example.

  4. Posted 1 September 2006 at 12:04 am | Permalink

    Much of my traffic does come from this particular hint. :-) Perhaps DokuWiki could incorporate it in the mainline.

    Its performance was slow for me too; however, bandwidth was costing me real money and I don’t use my wiki so frequently that the slowness bothers me. Do document and contribute back any improvements you make!

    Thanks for visiting.

  5. hubi
    Posted 13 September 2008 at 10:15 pm | Permalink

    Hm, any idea, why this is not working for me? I installed bbpress today and setup compression there with one click.

    But no way with dokuwiki http://www.pipeboost.com/GetReport.asp?URL=http%3A%2F%2Fhubionmac.com%2FAppleScriptWiki%2Fdoku.php

  6. Posted 14 September 2008 at 5:25 am | Permalink

    GZip compression can be enabled in recent DokuWiki versions by enabling the gzip_output option.

Post a Comment

Your email is never shared. Required fields are marked *

*
*