Optimizing Your WordPress Install – Reloaded

/ Wordpress / by Paul Robinson / 7 Comments
This post was published back on January 21, 2012 and may be outdated. Please use caution when following older tutorials or using older code. After reading be sure to check for newer procedures or updates to code.

It’s not nice and I don’t really want to say it, but it’s true. WordPress is a pig. A big hungry pig. Well when it comes to memory it is. It’s still one of the best, if not the best, CMS/Blog application out there but it’s hungry and as a owner of a website built on WordPress you have to deal with that.

What Do You Mean, Hungry?

Don’t get me wrong there are other applications out there that use much more memory, but for those on shared servers or even those (like me) who are trying to save money by squeezing as much out of their VPS (Virtual Private Server) as possible, WordPress can use a lot. For example. A fairly large custom application I built using Codeigniter that has quite a large database backend (over 675,000 rows) for a project uses 1MB of memory per page load, my WordPress blog uses between 30MB – 42MB (without Caching).

What Can I Do About It?

Well first there are a few simple things everyone can do with their WordPress install.

Deactive Unneeded Plugins

Deactivate & delete any plugins you aren’t using any more or could live without. Some plugins add a bigger memory overhead than others, but every little helps when it comes to saving memory.

Optimize Your Theme

Optimize your theme. This one is difficult if you aren’t familiar with WordPress theme authoring. Basically you want to make sure that your theme uses the least amount of loops, and does everything as efficiently as possible. If you have 2 loops, but you could use one, then use one instead. Basically the idea is to remove anything not needed, and optimize anything that may be inefficient.

Install A Cache

The final thing is to install a caching plugin. There are a few around, but the two I trust the most are W3 Total Cache, and WP-SuperCache they are both excellent but have different strengths. I have found WP-SuperCache to be the easiest to use, but W3 Total Cache leverages a larger range of technologies should your server support them.

Remove TimThumb

As much as it has been improved & any vulnerabilities patched, I still advise against using TimThumb. Especially if you are using an older theme that hasn’t had it’s version of TimThumb updated. The main reason is that you can now use the built in thumbnail generator in most cases. It requires playing around in your theme & if you aren’t familiar with the development side of WordPress you may want to hire a WordPress developer, such as myself, to alter your theme to use the post thumbnail system now included in WordPress. This can help a lot as you are not relying on thumbnails to be generated by a visitor, they are instead generated when you upload them.

Swap To ImageMagick

This is now done automatically by the WordPress core. If ImageMagick is available WordPress will use it.

What About Server Optimization?

Server optimization is difficult since you generally need a VPS to take any of the actions that would really improve performance. Hopefully though those that do have a VPS will find this useful.

Make Sure Caching Is Effective

First thing is to make sure your caching plugin is actually working. Some servers I’ve worked with have strange quirks that stop caching from working properly. First make sure you aren’t mistaking the fact you are logged in for not caching, most popular caching plugins have an option not to cache for logged in users, if you have it turned off or you aren’t logged in, then read on.

You can check caching is working quite quickly. First view the source code of the page & scroll to the bottom, if there is a comment there about caching there is a good chance it’s working. However I have seen the odd time when the comment is there but caching is still not working. How do we check then?

If the comment is there, but you still aren’t convinced your site is being cached, try navigating to the cached folder via FTP and see if there are files being made. If the files are there, but you still aren’t happy, try comparing the speed of a page load when caching is enabled with when caching is disabled. You can use Chrome’s network tools or Firebug to check the speed of a page load. If caching is working chances are you’ll notice quite a large difference. My page speeds have gone from between 780ms – 1.2s to 300ms – 450ms due to caching.

If you are using W3 Total Cache you can also see if your server is outputting the special header sent by W3 Total Cache, using Firebug or Chrome’s Dev Tools.

Swap Your Webserver To Nginx

One final method you can use, and I would strongly advise, is to switch from Apache to Nginx. I do caution you though that it can require a fair amount of dedication & a little knowledge of Shell & FTP is helpful. Why? Well nearly everything on the internet is written for Apache because it is the most commonly used web server so things require a bit of customizing to work. The benefits however are that Nginx scales in a much more efficient manner to that of Apache.

As I said switching to Nginx from Apache can be difficult so here are a few tips I learnt when I switched. First find out where you can place custom Nginx rules. These are the Nginx equivalent of htaccess rules used by Apache. Then you need some basic rules so that WordPress can use pretty permalinks. Here are the ones I found to work the best:

In Nginx ‘if’s or conditionals are normally said to be ‘evil’. So this is the most efficient way I have found to use for the default WordPress rewrite rule.

If you are using WP-SuperCache I’m afraid I don’t have a confirmed to be working Nginx rule set for that. You could however try this:

I’m afraid I don’t know who to give credit to for these as I found them a while ago before I switch to using W3 Total Cache & ended up never using them. Thank you whoever wrote them & please, if you do end up using them, let me know if they do actually work.

If you are using W3 Total Cache you are in luck as that plugin has Nginx rules ready for you on it’s install page. If for some reason it can’t make them for you, or your Nginx rules have to be located else where just copy them from the ‘install’ page of the W3 Total Cache plugin paste them into your file and you should be ready to go.

That’s It

That’s about it. There are other ways you can optimize things, but these are the few things I have found to help balance my memory usage the best. As always your mileage may vary, but please let me know if you have any questions, problems, or anything you’ve done that has helped improve your servers memory use.

As always thank you for reading, and don’t forget I’m available for hire for WordPress related work & I can provide quotes for other work. Details of prices are on my Hire Me page.

7 Comments

Author’s gravatar

theme’s can probably start making more use of the Transient API too. i try to use it any time i am getting posts for a secondary loop.

Reply
Author’s gravatar author

Hey Kathy,

Actually that’s a great idea. I’ll try and add transient API use into this post and make a tutorial on using the API in general. I used it once to cache post results when a client wanted to show a single post from 5 categories so that it didn’t stress the server too much trying to do 5 queries everytime the page was loaded.

Author’s gravatar

Use CDN with W3 Total Cache. Then your pages load faster due to serving cache and media from faster and closer servers and reducing load on your server.

Also if you use ImageMagick Engine your image get sharper, yes, your photos Exif and geo tagging can be viewed which is cool. But due to preserved meta data they appear as not optimized well. Check them in Google PageSpeed tool.

Reply
Author’s gravatar author

Hi Anton,

Yes, CDNs are a great idea & can help speed things up a little for those outside of the area where your server is located.

Services like CloudFlare offer CDN, Caching & security and are great, but a little awkward to setup (have to mess with DNS) for the non tech savvy.

I disagree about ImageMagick. I find the increase in performance in general with ImageMagick outweighs the lack of optimized images.

However if you need images to be optimized you can easily do that by playing around with the ImageMagick commands. Quality, is a big one. Sampling, can help too. You can also remove the exif & profile data by adding +profile "*" to your mogrify or convert commands. If making thumbnails use the -thumbnail option to optimize images a large amount, and finally if you need to sharpen images use -sharpen and -adaptive-sharpen. It’s been reported using certain combinations of these options can reduce file sizes even lower than Photoshop, however I can’t vouch for that.

Older Comments
Newer Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

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

I'll keep your WordPress site up-to-date and working to its best.

Find out more