Last year, I wrote a post about using gettext to localize PHP web pages. Gettext makes it easy to maintain the translations and always provides a fallback locale. But is it fast?
I created a simple web page to compare the performance of various localization methods for PHP. It only contains 3 localized strings and does not use advanced features of gettext (e.g. plurals). I wrote a version using the gettext PHP extension (”gettext Ext.”), one using PHP-gettext (”gettext PHP”, a gettext implementation written in pure PHP) and a version that does not use gettext at all, instead it uses an array that contains all the translations (”String ID”).
I put all three pages on a Debian machine with the latest Apache 2.0.55 and PHP 5.1.2 and used the Apache HTTP server benchmarking tool to measure the performance of the different methods. I always made two tests - using the default locale (English) and a translation (German), because gettext does not have to use a locale file for the default language (it’s embedded in the page).