navigation

PHP opcode cache and WPMU

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

PHP is a scripting language. Which means that everytime you run a PHP script, and interpreter is run that reads the script, parses it, and compiles it in a program that is executable by the system it runs on.

What this means is that even though all your users accessing your site use the same set of scripts, those scripts get re-read, re-parsed and re-compiled for every single request that hits your server. Highly innefficient. This results in way too many useless disk accesses and too much useless CPU processing. Combine this with the thousands of PHP scripts present in a software like WordPress (MU), and you get a lot of unnecessary load on your servers.
To solve this issue, one can use PHP opcode cache programs. What these do is they plug into php, and keep in memory a cache of the compiled version of programs, which eliminates the unnecessary compiling of PHP scripts. Usage of such cache on our systems has proved to show a 25 to 40% improvement in CPU usage, and quite a disk access improvement too although harder to measure.
Three popular free PHP caches are APC (Alternative PHP Cache), eAccelerator and XCache. Zend also provides one with its platform (however it’s not free).

We’ll discuss only APC further here. Although it is considered slightly slower than its counterparts (studies have shown it 5-10% slower), we picked it for several reasons : it is developped by the developpers of PHP, which can only be good, it is more stable than the others we tried (less segmentation faults), a bit more configurable, and it offers an object cache which can come in handy as well as discussed in another section on this blog.

I won’t cover here in detail how to install APC, for which if you google a bit you’ll find plenty of documentation depending on your system. However I’ll focus a bit more on WPMU specifics to using APC.

First, check the following configuration aspects :

- apc.shm_size : this is a very important setting, it tells APC how much memory it can use to store the caches of your scripts. It is very important because if it is too small it will get full, and in our experience, APC with full memory triggers a whole lot more segmentation faults than if it has some room to operate. If your server only runs WPMU, you can give APC 32M of shared memory, and if you have some extra memory available, 64M will make it comfortable. Be sure to check in your browser apc.php once in a while to see the status of your cache, and make sure you give it enough memory for that piechart not to become too red.

apc.jpg
- apc.num_files_hint : this is not extremely important, but if your server runs WPMU only, you can set its value to something around 500-700. Look in apc.php after a day of running how many files are cached to get a better estimate for your system.
- apc.filters : this is extremely important and somewhat specific to WPMU. The file kses.php in wordpress MU’s distribution triggers segmentation faults under some conditions (not systematically though). Once it segfaulted once, all your pages will segfault too, returning the « dreaded blank page ». I’m not sure why, but kses.php also triggers segmentation faults with eAccelerator and XCache. These can be a nightmare because you never know whenthey’re gonna show up. Your best shot at this problem is to filter out kses.php from caching using this variable. Do this by chaing the corresponding line in apc.ini to :

apc.filters = « kses\.php »

If you also use WP-Cache plugin, I suggest also filtering out cached files :

apc.filters = « (kses\.php)|(wp-cache-.*\.html) »

Now restart apache, and watch the magic ! :)

Commentaires»

1 2
  1. pardon my ignorance, but where is the path to apc.ini? I checked in my /etc/php.d/ folder but did not find it there. Does it need to be first enabled before it appears there?

  2. scratch that last post, I figured out when you said apc.ini you were really talking about php.ini, or at least you need to create the apc.ini file in the php.d folder, because it isn’t there by default!

    I’m taking a look at the stats in my apc.php file as we speak.

  3. Where i must put apc.ini?

  4. apc.ini must be in /etc/phpd/apc.ini
    Gilles

  5. Below you will find the link to some sites that we think you ought to visit.

  6. The information talked about within the report are some of the most effective readily available

  7. Here is a great Weblog You might Obtain Interesting that we Encourage You

  8. check below, are some totally unrelated websites to ours, however, they’re most trustworthy sources that we use

  9. the time to study or go to the content or web sites we’ve linked to below the

  10. we like to honor quite a few other web websites around the net, even when they aren

  11. we like to honor lots of other online web pages around the internet, even when they aren

  12. check beneath, are some entirely unrelated internet sites to ours, however, they’re most trustworthy sources that we use

  13. Here are a number of the web sites we suggest for our visitors

  14. very handful of web-sites that take place to become in depth beneath, from our point of view are undoubtedly very well really worth checking out

  15. check beneath, are some absolutely unrelated websites to ours, however, they may be most trustworthy sources that we use

  16. usually posts some pretty exciting stuff like this. If you

  17. Here is a good Weblog You might Come across Exciting that we Encourage You

  18. Here is an excellent Weblog You might Come across Intriguing that we Encourage You

  19. check below, are some absolutely unrelated internet sites to ours, nevertheless, they’re most trustworthy sources that we use

  20. usually posts some pretty fascinating stuff like this. If you

1 2

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