Speeding up Gallery2

1 minute read

I have been using Gallery2 for my private picture collection for quite some time. It's a great piece of software that shows how to write PHP code. Unfortunately, all the abstraction layers make it quite slow without additional help. I did three things to speed things up a bit:

  1. Use lighttpd (doesn't give that much of a performance gain, but at least a bit). This requires PHP to run as FastCGI.
  2. For PHP: use XCache (makes a huge difference as all the classes don't need to be recompiled for each request)
  3. Use lighttpd's X-Sendfile support to make the webserver send the pictures to the client and get the load away from PHP.

For point 3 I needed to modify Gallery2, the patch (for Gallery 2.3) is available here:

To enable sendfile support, add this to your config.php:
$gallery->setConfig('useSendFile', true);

And don't forget to enable X-Sendfile support in your webserver's configuration!

This patch does not require Lighttpd, I've tested it with Apache and mod_xsendfile, too. Please note that Sendfile (as well as XCache) do not work with lighttpd 1.4 as soon as mod_cgi is enabled (they silently stop working, error reporting is not one of the strengths of lighttpd).

Of course I did no benchmarks (*gg*) but things feel much snappier now, and that's all that counts.