Julien Perez' blog

Aller au contenu | Aller au menu | Aller à la recherche

Tuesday 4 September 2007

rbackup 0.5

Et voilĂ  ! I just released a new version of the micro software rbackup (which is a copy of the design of rsnapshot, only this time it's using rdiff-backup instead of rsync). Check out the official website for more information: http://rbackup.lescigales.org/

Thursday 23 August 2007

mod_expires.c

In order to maximize the performances on lesCigales.ORG host, I decided to start experimenting with the module mod_expires of Apache, that could tell a reverse proxy to cache a page (by setting the Expires: header in the HTTP response).

But I found out an horrible truth: it is using the mime-type of the output and not the mime-type of the file to find out which configuration to use.

First of all, how is working mod_expires ? You configure it using mime-types and it will either say 'cache this data for X time from now' or 'cache this data until X time from the last modification of the file that generated the output'.

       ExpiresByType text/html "access plus 5 seconds"
       ExpiresByType image/gif "modification plus 5 days"

Then, after the Apache server processed the request, mod_expires looks at the headers of the response and compare the data in Content-type: with its configuration to find a match. If it does, it uses the mimetype found to set the time to cache the content, otherwise it uses a default value set by the following:

       ExpiresDefault  "access plus 15 seconds"

So basically what it means is that there is no way you can differentiate a cache setting for a static html file (which should relatively looong) and a text/html output generated by a PHP script (which should be quite short in order to keep data reliable). One word: Neat !

Finally to solve this issue, I hacked into the module and now, instead of using r->content_type for comparison, it uses use r->handler, which concretely means that everytime I will set something like this in the Apache configuration:

# Static HTML files will be cached for 7 days:
       ExpiresByType   text/html       "modification plus 7 days"
# For everything (but mostly for PHP, CGIs applications):
       ExpiresDefault  "access plus 15 seconds"

it will indeed cache text/html files for 7 days after their last modification and cgi-scripts (or all the rest) for 15 seconds after the first access. That's exactly what I wanted, hooray !