0

I have been using PHP's gettext extension for a while and I am satisfied with its capabilities. I was wondering if there was a point in writing a class that will cache the strings from the .mo file to a Memcached server, for example.

Can I benefit from caching strings, collected by gettext or should I leave it as it is?

thexpand
  • 641
  • 13
  • 28

2 Answers2

1

No benefits

No, you can't benefit from caching your .mo files to external cache like Memcached. The native gettext extension have its own caching built-in. Due to the fact that PHP's gettext functions retrieve translation only from a .mo file, makes it impossible for PHP to get the translations from a Memcached server.


The wrong solution

The only option is to cache the strings from your .mo file as a string array in your Memcached server, but that would make the method of getting translations slower than the native one, so there is no point in making that.


Conclusion

Use the native gettext, it has its own caching algorithms. Loading up your code with external caching classes may result in useless code, which will slow down your site performance, rather than making it faster. Moreover, you will already have lost your time writing the external caching class.

thexpand
  • 641
  • 13
  • 28
0

If you're using the native gettext extension, it is already caching .mo files internally. You'll find many a question on here on how to get it to refresh because its cache can be so aggressive sometimes.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • I know about the cache that PHP's gettext have and the struggles with it. I have to restart my php-fpm when I do a re-index of the files. I just want to know if there is any point in caching it to a Memcached server. Will it be faster? – thexpand Feb 19 '14 at 08:52
  • Why would you build yet another cache around an already cached system? How would you get gettext to use the data in the memcached store? – deceze Feb 19 '14 at 08:55
  • 1
    Hm.. you are right. If I cache it in the Memcached server, I won't be able to use the gettext functions, leading me to the only option of making a cached string array in memcached, which will cause a slowed down, rather than fast, procedure. Thanks! – thexpand Feb 19 '14 at 09:04
  • I gathered the information from our discussion and wrote it as a whole answer to be there for people to see. – thexpand Feb 19 '14 at 10:02
  • What about multiple servers? I have multiple servers and I don't want the .mo files in my git because they are difficult to merge when conflicts arise. And it is very slow to create the .mo files on every server every time we deploy code (I don't have po files the mo files are built from a database). – byoungb Oct 05 '16 at 20:10