WordPress Performance opcode cache

If you are running WordPress on a VPS or dedicated server, a quick way to optimize performance is to install a php opcode cache. To understand why, you need to first understand how php processes a request.

A php request goes through the following steps:

  1. Read
  2. Parse
  3. Compile
  4. Execute
  5. Output

For every WordPress page requested, the php engine must go through all 5 steps. A php opcode cache keeps the complied php code in memory, thereby eliminating the 1st 3 steps above. Fortunately for you, installing and configuring a php opcode cache is simple. There are many php opcode caches, but my favorite is the alternative php cache (apc).

Here are the instructions for installing the alternative php cache (apc) on an ubuntu server:

1. Install php-apc

apt-get update
apt-get upgrade
apt-get install php-apc

2. Configure php-apc by editing the apc.ini file

vim /etc/php5/apache2/conf.d/apc.ini

Add the following to the apc.ini file (where 20 the amount of RAM allocated to your apc cache. I’ll discuss how to find the size needed later):

apc.shm_size=20

3. Restart apache

/etc/init.d/apache2 restart

4. Verify Status

To check the status of you apc opcode cache you can install a monitoring script from http://git.php.net/?p=pecl/caching/apc.git;a=blob_plain;f=apc.php;hb=HEAD by uploading the apc.php script to your web server. Use your web browser to browse to this script page and you will see a dashboard of the status of the apc opcode cache.

One of the items you should pay attention to is the Cache full count. This tells you how many times that the apc opcode cache ran out of memory.  You should try to raise the amount of RAM you have allocated to apc to avoid this. On a server that I administer I have the cache set to 60, and this is enough to have WordPress (including plugins and themes) and phpMyAdmin in the apc opcode without ever running out of memory in the cache.

If you have any questions, please leave a comment below.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.