Other posts

Compress Your repo XML

Outofscope 2008-06-06

I thought it had been already done by everyone, but it turned out not...

In this post I'll describe a method of compressing an AppTapp Installer repository XML file, both static and generated by a PHP script.
I think there is no need to say that this will save traffic and speed up the refreshes to end users :)

1. Compressing static repo XML

(Method is correct for Apache webserver with mod_rewrite turned on)

  1. Simply gzip Your XML file. Lets assume it's named repo.xml

    Then in MacOSX/Linux/FreeBSD You can simply run
    gzip -c repo.xml > repo.xml.gz
    in a command shell.
    And in Windows You can use the free 7-zip program to compress Your file (make sure to select the GZip compression method)
    So, now we have repo.xml.gz, nearly 10 time smaller than original one.

  2. Put repo.xml.gz in the same directory where Your original XML file resides.

  3. Create .htaccess file (or modify the existant one) and put it next to Your repo files. Put the following lines into it:
    <files "repo.xml">
    RewriteModule on
    RewriteRule repo.xml repo.xml.gz
    ForceType application/x-apptapp-repository
    AddEncoding x-gzip .gz
    </files">
Your repo will still be available at the old address, e.g. http://domain.com/repo.xml

2. Compressing output of a PHP script
  • If You use PHP script from Nullriver or similar, then You need to search index.php for the row
    die(generateIndex(__PLISTS_PATH__));
    and replace it with two rows
    header("Content-Encoding: gzip");
    die(gzencode(generateIndex(__PLISTS_PATH__)));
    That's all!

  • The other way You need to add
    header("Content-Encoding: gzip");
    before the output starts, and pass all the output through gzencode() (as a single piece, i.e. accumulate output in a variable and pass it through the function at once)

Please feel free to ask question and suggest Your improvements on our forum!

There are no comments yet, You can submit the first one.

To submit comments You should register and sign in
add to del.icio.us