navigation

Full page cache with WP-Cache in WPMU

This is part of the caching for WPMU section of this blog, make sure to browse it for more information !

WP-Cache is quite an awesome plugin wor WordPress when you want performance improvements. Unlike the built-in object cache, WP-Cache works by not only caching objects, but caching complete HTML versions of a blog’s pages on disk and serving them directly until the cache is purged. This allows for super-fast page delivery, since it avoids all connections to database and script-loading.

Note : I won’t post here any of the files we actually use in our own implementation of WP-Cache (they are often too specific to our own systems and solutions), but will give the necessary advice to implement it properly.

Applied to WPMU, there are a number of factors to consider before you jump in and save your servers by implementing WP-Cache :

- You do not want to enable it on all blogs. WP-Cache writes a lot on disks (every page that is visited the first time, the first time after it was modified, or the first time after it expired). If a cached page isn’t visited at least a few timeswhile ithas an up-to-date cached versions, you probably spent more performance saving the page to disk than you saved with this cache. Also, a blog which receives tons of comments might not benefit that much from WP-Cache, because comments flush this cache and trigger a new disk write. We suggest having a static list of blogs for which you want the cache enabled, and use something along the lines of :

if(in_array(currentblog,listofblogs)) { define(« WP-CACHE »,true); }
- You need to be careful with your plugins. Some plugins *need* to have some dynamic information displayed on page to work properly. For unblog.fr, such plugins include : number of users online plugin (no point in this if you display a cache), statistics plugin (you need to log hits for your stats to be relevant even when the page is served from cache, spam karma 2 (needs some dynamic hash inserted in the page to ensure you actually loaded it before submitting a comment), referers plugins, and a couple of others.

WP-Cache is not very clear about what to do to keep some elements dynamic in the cached pages.

I will go through what needs to be done for SK2 to give you an idea of how you should adapt your plugins to keep things working correctly. The problem with SK2 is the « payload » plugin, which inserts a dynamic piece of HTML in the page to ensure it was actually loaded before submitting a comment. The existing function of the plugin we’re interested in reads :

function form_insert($post_ID)
{
$seed = $this->get_option_value(‘secret_seed’);
if (empty ($seed))
{
$seed = sk2_rand_str(10);
$this->set_option_value(‘secret_seed’, $seed);
$this->log_msg(__(« Resetting secret seed to: $seed. »), 5);
}
$time = time();
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$payload = md5($time . $seed . $ip . $post_ID);
echo « « ;
echo « « ;
echo « « ;
}

Good. Now what we need is to make sure those « input » tags stay dynamic even when served from the cache. To do this you must first inform WP-Cache that this section is dynamic, then tell it what function it’ll have to call to generate the dynamic information when the page is loaded from the cache : you can’t use your default plugin’s functions, because your plugin won’t have been loaded when WP-Cache serves the « static » page ! So you can modify your function like this :

function form_insert($post_ID)
{
$seed = $this->get_option_value(‘secret_seed’);
if (empty ($seed))
{
$seed = sk2_rand_str(10);
$this->set_option_value(‘secret_seed’, $seed);
$this->log_msg(__(« Resetting secret seed to: $seed. »), 5);
}
$time = time();
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$payload = md5($time . $seed . $ip . $post_ID);
echo « « ;

echo « « ;
echo « « ;
echo « « ;
echo « « ;

}

The « mfunc » tag tells WP-Cache that everything within it is dynamic, and will have to be replaced with whatever the function cached_sk2_javascript_payload will return.
Now all what’s left to do is create this function in a scope that’s visible from the WP-Cache scope (typically at the bottom of the advanced-cache.php file you’d have :

function cached_sk2_javascript_payload($seed,$postid) {
$time = time();
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$payload = md5($time . $seed . $ip . $postid);
echo « « ;
echo « « ;
echo « « ;
}

You can deal in this manner with any of your plugins that need dynamic content to be output or queries that need to be run even on cached pages : surround the dynamic page with the mfunc tag in the original plugin, then create the appropriate function and insert it in advanced-cache.php.

You’ll probably run in some trouble before you make everything work correctly in combination with WP-Cache. To keep you motivated, take a look at this graph, it shows the CPU usage on one of our HTTP servers the day we enabled WP-Cache for the top 30 most used blogs in our network. 60% decrease of CPU load !
wpcache.jpg

Using this plugin is by itself cutting our IT expenses almost in half. Good luck !

Commentaires»

1 2 3
  1. We prefer to honor a lot of other world-wide-web websites around the net, even if they aren

  2. Sites of interest we have a link to

  3. check below, are some completely unrelated websites to ours, however, they are most trustworthy sources that we use

  4. although sites we backlink to beneath are considerably not related to ours, we feel they are really worth a go as a result of, so have a look

  5. Here is an excellent Blog You might Find Interesting that we Encourage You

  6. The info mentioned inside the post are several of the best obtainable

  7. we came across a cool web site that you simply may well appreciate. Take a search in case you want

  8. just beneath, are various entirely not associated web-sites to ours, however, they may be certainly worth going over

  9. the time to study or pay a visit to the material or web-sites we’ve linked to beneath the

  10. Here is a good Blog You might Obtain Interesting that we Encourage You

  11. here are some hyperlinks to web-sites that we link to since we assume they are worth visiting

  12. always a large fan of linking to bloggers that I enjoy but don

  13. the time to read or take a look at the subject material or web sites we have linked to below the

  14. please take a look at the sites we comply with, which includes this one particular, as it represents our picks in the web

  15. we prefer to honor a lot of other world wide web web-sites around the net, even though they aren

  16. here are some links to sites that we link to mainly because we think they are really worth visiting

  17. that will be the end of this report. Right here you will find some websites that we assume you

  18. check beneath, are some entirely unrelated sites to ours, having said that, they are most trustworthy sources that we use

  19. although websites we backlink to beneath are considerably not associated to ours, we really feel they are really really worth a go as a result of, so have a look

  20. always a big fan of linking to bloggers that I enjoy but do not get a great deal of link like from

1 2 3

Laisser un commentaire

Le Web Rémunéré |
les codes pokemon |
........l'univers de TINTIN... |
Unblog.fr | Créer un blog | Annuaire | Signaler un abus | nateeve05.blogee.com
| BOUCHEKFA
| riadsfes