4

I'm currently struggling with gettext in PHP.

Gettext use cache. That's a good thing, but when I update my translations, I can't access them, which is annoying.

I read we can't flush the cache apart from restarting the web server, which is not a viable solution. Other people use copy of the .mo files with a different name to force them to be loaded again.

First question

I was searching for how long gettext caches the files in memory to consider whether it's acceptable for my application to wait that time before the strings appear. But I couldn't find that information... Is the duration infinite?

Second question

I can't imagine a such popular project as gettext hasn't come with a solution to overcome this problem. Is it PHP-specific?

Thanks in advance for the anwsers I will have. Regards.

Savageman
  • 9,257
  • 6
  • 40
  • 50
  • check out http://stackoverflow.com/a/13629035/245428, no restart apache, nor different domain needed. – xiaoyi Nov 29 '12 at 15:42

3 Answers3

5

Every app that uses gettext always uses the cache while the app is running, the file is probably opened at start-up/first use and then stored in memory until closed down. PHP is continually running as part of apache (via mod_php) rather than starting up and closing down.

If you use php-cgi it doesn't have this problem as PHP is started by apache when needed.

Gettext was originally developed for desktop apps, not long running server side applications that the "sysadmin" doesn't have control over stopping and starting. You wouldn't expect a desktop app to change while running it.

dsas
  • 1,650
  • 18
  • 30
  • 1
    So 1. the cache is infinite and 2. it's PHP-specific, indeed (well, not ONLY PHP, but I get the thing). Thanks! – Savageman Oct 29 '11 at 18:21
1

For the same reason we've chosen not to use gettext built into PHP, but rather php-gettext. You will loose a bit of performance (nothing we could measure), but you have better flexibility.

Michal Čihař
  • 9,799
  • 6
  • 49
  • 87
  • Thanks, we ended up with a custom solution base on arrays which are converted abck and forth into .po files syntax. – Savageman Nov 16 '12 at 13:20
0

php-gettext works with streams seems a bit outdated. Worrdpress last time I checked reads the files and converts them to Arrays...not really effective.

I still prefer to use gnu gettext , in my case I needed to restart phpfpm by doing:

service php5.6-fpm-sp restart.

Hope is useful to someone else.

chema
  • 531
  • 6
  • 15