Cache Translation Object

A WordPress plugin

This plugin is currently not maintained and has not been tested for a few WordPress releases. I will update it eventually, but for now use with caution!

Substantially increase performance of localized WordPress by caching the translation (l10n) object. Supports multiple languages.

Description

On every pageload a localized WordPress site spends a huge amount of time setting up the translation (l10n) object. Startup for a localized site can be almost four times slower than an untranslated one.

This plugin stores the translation object between pageloads so it only has to be created once, resulting in significantly better performance (performance graph included with screenshot).

Plugin supports caching multiple languages (if you use a multi-language plugin).

Available storage: Plain file, APC (Alternative PHP Cache), or SHMOP (Shared Memory)

graph-1-284

Download

You can always find the latest version to download here.

Installation

  1. Download and extract plugin files to a folder in your wp-content/plugin directory.
  2. Activate the plugin through the WordPress admin interface.
  3. Select an available storage on options page (see FAQ for more details if necessary).
  4. File storage needs write permissions (once) to wp-content after install to set up the directory used for storage (wp-content/cache/l10n-cache). Once set up is finished wp-content should be kept write protected.

Requires at least WordPress 2.8, tested up to WordPress 2.8.5.

Multiple WordPress sites on same host

APC and SHM is a shared storage. This means all sites on host using these storages types will share the same cached objects. If not all sites use the same WordPress version and plugins that is a problem. Different locales are stored as separate objects so is not an issue.

If sites differ please use file storage which store objects in a separate directories for each installation.

Screenshots

  1. Administration interface in WordPress 2.8.4

FAQ

  • What storage is fastest?
    The exact numbers will depend on your configuration but in my testing APC is a tiny bit faster than shared memory which is a bit faster than plain file storage. Take a look at the graph above.
  • What is APC (Alternative PHP Cache)?
    “The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. Its goal is to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.” It is not usually installed with PHP by default.
  • What is SHMOP (Shared Memory)?
    It is a PHP interface to handle Unix shared memory segments. It should be available by default on Linux/Unix servers. On Windows it may be possible to enable in PHP.ini. On some older systems (and Windows) shared memory may have problems if multiple languages are used on same site. (If `Open slots` in the debug storage information keeps decreasing you should choose a different storage type.)
  • How do I make the file writable?
    http://codex.wordpress.org/Changing_File_Permissions
    File storage write files to wp-config/cache/l10n-cache/. These directories will be created automatically if wp-config is writable at first use. Once these sub-directories are created wp-config should be kept write protected.
  • I want to change where the file is written
    Currently you’ll have to do it by hand. Find the define at the top of wp-content/plugin/cache-translation/cache-translation-file.php

Change Log

  • Version 1.1
    • Rewritten to cache multiple locales separately
    • Split out admin functions into separate file
    • Handle old SHM with questionable delete behaviour by relocating as necessary.
    • Add storage debug info link
    • Do not default to any specific storage type, make user choose
    • Tell admin when something is wrong (also better error handling).
    • Added plugin localization
    • Added Swedish translation
  • Version 1.0
    • Initial release

18 Responses to “Cache Translation Object”

  1. mark k. says:

    Sounds like an extremely cool idea. Will have to find some available time and test it.

    There is another optimization path - separation of the full translation, and the translation of what is found under the wp-includes directory where the first is loaded only when a user enters the admin interface, and otherwise the second is being loaded.

    I once tried to follow this idea and it works, but I didn't find a solution which do not require changing core files which makes this thing hard to maintain.

  2. Yes, I did some tests with splitting the translation files into non-admin vs full and it is a real performance gain (also results in less memory vasted -- l10n is a large object).

    It would however require pre-processing the translation source files. The files WordPress sees (MO files) are binary files produced from structured text files (PO files) and during that translation information regarding where each string is used is stripped out.

    But anyway, it is a good idea with a surprisingly large performance payoff. The translation system is one of the most expensive in a localized WordPress, and there are quite a few ways it could be optimized.

  3. ovidiu says:

    I am on my own server, linux, hosting several wp installations. whats advisable as storage?
    file seems to work fine.

    btw. how can I test if the plugin has any effect on my wp installation?

    besides, the vhosts all run suPhp, so chosing SHMOP as storage, will there be problems i.e. mixing up of localization caches?

  4. ovidiu says:

    btw. the settigns page is a bit misleading: when deactivated, the setting says deactivated with a checkbox. I thought I have to check it to disable it... might want to rethink that...

  5. ovidiu,

    File storage works fine. APC/SHM is slightly faster but I was surprised at how little difference it actually makes. I guess the file get cached by the OS unless you are low on memory.

    Unless all wp installations share the same version, language & translated plugins you MUST use file storage as APC/SHM is shared between all installations.

    For benchmarking apache comes with Apache Bench. For example 50 page loads, 1 concurrent:
    ab -c 1 -n 50 http://example.com/

    Test it with plugin enabled and disabled to see difference, though you might want to reload the page after enabling plugin to let it cache the object first.

    (chart above is average total connection time for 400 pageloads with 4 concurrent connections)

    And yes I agree that the activation checkbox text is a bit misleading -- will change for next version.

  6. ovidiu says:

    thanks :-) will use file based storage.
    hit a similar problem when playing with wp super cache plus => that version caches to eaccelerator instead of filesystem, but found out php accelerators don't work with suPhp :-(

  7. Marcelo says:

    Very interesting concept. It works great and has speeded my load times :)

  8. Marcelo says:

    By the way, shmop works significantly better. I've tested it under WAMP (Linux 2.2, PHP 5.2.9, Windows XP SP3). I'd have to recompile apache with shmop and APC in order to test it in my web server, but I can say that under Windows this plugin works like a breeze. Congrats.

  9. I tried the plugin. But all I get is this:

    Cache Translation Object: Translation object already exists! Plugin collision?

    But there is no there translation or caching plugin enabled.

    This happens on Windows XP and on Linux (vhost).

    Any ideas?

  10. It should only happen if some other plugin loads their textdomain before the cache translation object plugin is loaded.

    In the future I'll try to work around this.

    What other plugins do you use?

  11. Thomas Scholz says:

    Oh, that makes sense.

    Translated plugins I use:

    • AddQuicktag
    • Akismet
    • Google XML Sitemaps
    • HeadSpace2
    • Search Everything
    • Subscribe To "Double-Opt-In" Comments
    • WordPress Database Backup

    Your plugin should probably start with the highest priority.

    Regards
    Thomas

  12. 'Subscribe To "Double-Opt-In" Comments' load textdomain at plugin file load time and apparently gets parsed first.

    (it should probably be moved to, for example, plugins_loaded action to allow other plugins to register their hooks)

    I'll fix this error condition in next release -- hopefully tomorrow.

  13. Sarha J says:

    I like to gamble a few pounds each month and I'm thinking about trying an online casino. Are online casinos safe? Which online casinos give the best bonuses?

  14. Surrey says:

    Does this plugin work ok with the global translation plugin? Thanks

  15. Lee says:

    I'm using the W3 Total Cache plugin, is there ant point using this translation as well?

    Lee

  16. leon says:

    Woul'd it work with wp 3.6 ?

  17. Björn says:

    WP Performance Pack can speed up your WordPress localization by using native gettext or an alternative MO implementation: http://wordpress.org/plugins/wp-performance-pack/

  18. justpaste.it says:

    This looks a lot like my shower we bought recently,
    extremely pleased about it for individuals found on the fence about buying one, do it,
    you will not regret it

    Feel free to surf to my web-site steam shower sauna (justpaste.it)

Leave a Reply