» WordPress Plugins » Reduce the server load your wordpress blog creates

Kevin MuldoonReduce the server load your wordpress blog creates

Written by Kevin Muldoon from System0 on October 29, 2007

Whilst working on a post today my server went down for 20 minutes or so. This also happened a few days ago so I contacted my hosting company Wired Tree and asked if they could look into what was causing it.

I got this reply :

It is hard to say what would use more memory. I have seen one single wordpress site cripple an entire server when it got a huge spike in traffic. It really doesn’t scale very well.

Some users have installed this plugin and seen some good results : WP Cache 2. It makes static pages out of your dynamic content so the server doesn’t have to access the mySQL database to get the information every time someone visits the site.

I know that forums can use up a lot of resources on a forum but I always assumed that most blogging platforms had no problems in that respect. There are a lot of reasons why PHP scripts can use up a lot of memory but the two main reasons tend to be that (1) The server needs to access many different files to display a page and (2) The server has to access the MYSQL database a lot.

Installing the plugin

You can download the WP Cache 2 plugin from this page. Make sure that your wp-content/ directory is writeable so that the plugin can set everything up. If you don’t do this you will get an error which says :

advanced-cache.php link does not exist
Create it by executing:
ln -s /WP/wp-content/plugins/wp-cache/wp-cache-phase1.php /WP/wp-content/advanced-cache.php
in your server

You will also have to add ‘define(’WP_CACHE’, true);‘ to your wp-config.php file manually if it is not writeable.

Downtime is bad for any website so any plugin which reduces server load is worth installing in my opinion. However, as you are about to find out, the plugin is far from perfect.

Using the plugin - Does it do what it’s supposed to?

I have only had the plugin live for 20 minutes so I’m not sure how much server load will be reduced. However, 20 minutes has been long enough for me to see exactly how it works. Basically what the plugin does is generate a static file for any page which is visited. So when a page is visited for the first time the plugin will generate a page and these pages are all listed in the wp-cache section of your options page like this :

WP Cache

You have the option to delete static pages which have been generated so that you can generate the static pages again.

Unfortunately, I noticed a problem with the plugin very quickly. The pages which the plugin are generating do not have ‘www’ attached to them. BloggingTips has been setup for the site to be live at www.bloggingtips.com and not bloggingtips.com yet the pages generated do not reflect this. For example, Mani’s post today has been generated as http://bloggingtips.com/2007/10/29/dealing-with-negative-comments-a-psychological-approach/ instead of http://www.bloggingtips.com/2007/10/29/dealing-with-negative-comments-a-psychological-approach/.

I am reserving judgement of the plugin until I have used it for a week or so and looked into how well it works. It is not clear if the plugin generates a new static page whenever a comment is added and regardless, it would be advisable to clear the cache every week or so that any design changes are implemented in the pages. Also, scripts which generate static pages tend to make the returning visitor refresh the page to see the current version of the page.

If you have used this plugin before then please leave a comment as I would love to hear about the pros and cons of the plugin. Likewise, if you know of any similar plugins which help reduce the load of your WordPress blog please let us know.

:)

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Bumpzee
  • E-mail this story to a friend!
  • Ma.gnolia
  • Print this article!
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
Written by Kevin Muldoon from System0 on October 29, 2007 | Filed Under WordPress Plugins
Unique Blog Designs

23 Responses so far | Have Your Say!

  1. Brian  |  October 29th, 2007 at 4:43 pm #

    Brian - Gravatar

    Kevin,

    you can get around the non-www problem by adding a couple lines to your htaccess.

    i do just the opposite, (as i don’t use www) like this:


    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    RewriteCond %{HTTP_HOST} ^www\.domain\.com
    RewriteRule (.*) http://domain.com/1 [R=301,L]

  2. Kevin  |  October 29th, 2007 at 4:45 pm #

    Kevin - Gravatar

    Hi Brian,

    I already have that in my htaccess for bloggingtips. I was referring to the static pages this plugin generates. Even though I have the redirect on my htaccess and even though I have my blog settings at www, the plugin generates the pages without the www extension

    thanks anyways :)

  3. Dave  |  October 29th, 2007 at 7:50 pm #

    Dave - Gravatar

    I’m not sure your .htaccess is correctly configured. When I try to remove the www from this post’s URL, I get redirected to the index.

    Typically, it doesn’t matter what you see wp-cache generate. The URL rewriting that mod_rewrite does is superficial, and the underlying URL where the document actually resides isn’t important.

    I am reserving judgement of the plugin until I have used it for a week or so and looked into how well it works. It is not clear if the plugin generates a new static page whenever a comment is added and regardless, it would be advisable to clear the cache every week or so that any design changes are implemented in the pages.

    By default, wp-cache will expire its cached copies after 5 minutes. You can set it and forget it. No need to manually delete anything.

    One thing that’s a good idea once you’ve enabled wp-cache is to configure PHP to compress its output, as mentioned on the wp-cache page.

  4. Kevin  |  October 29th, 2007 at 8:05 pm #

    Kevin - Gravatar

    Your right Dave, it isnt’t working. Pages are just being redirected to the index.

    I don’t believe its the code im using though. This is what I have in my htaccess file

    # redirect non-www to www
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^bloggingtips.com
    RewriteRule (.*) http://www.bloggingtips.com/1 [R=301,L]

    I have used this code for ages and it works fine. It is also currently used on a few of my other sites and there are no problems there. However, for some reason it is redirecting to the home page on bloggingtips.

  5. Dave  |  October 29th, 2007 at 8:15 pm #

    Dave - Gravatar

    Are you running one of the SEO WordPress plugins that tries to enforce the canonical name at the WordPress level? There could be a conflict there, maybe?

  6. Kevin  |  October 29th, 2007 at 8:28 pm #

    Kevin - Gravatar

    I used the ‘All in One SEO Pack’ but I just deactivated it and still, nothing. I then deactivated all plugins and checked again, still nothing. I thought you were on the right path with the plugins but it doesn’t seem to be causing it. Im stumped. I should probably speak to my hosting company.

  7. Kevin  |  October 29th, 2007 at 8:29 pm #

    Kevin - Gravatar

    I just tried the forums and everything is fine there (check any thread). Therefore it’s definately a wordpress issue.

  8. Dave  |  October 29th, 2007 at 8:32 pm #

    Dave - Gravatar

    One thing I’ve noticed about wp-cache is that you need to disable it when tinkering with plugins and design changes. It doesn’t invalidate its cached copies automatically when things like that change.

    I’d try disabling it and double checking those plugins again.

  9. Kevin  |  October 29th, 2007 at 8:42 pm #

    Kevin - Gravatar

    I disabled the wp-cache plugin and the all in one seo pack.

    Thing is, I would assume that if the wp-cache hack is switched off wordpress won’t look for the static page. I definately think it’s this plugin which is causing the problem but it’s unclear as to why or how…particuarly if it’s switched off.

  10. Kevin  |  October 29th, 2007 at 8:46 pm #

    Kevin - Gravatar

    I just deleted all the files in the cache directory but no change there (also, all wordpress pages seem to be affected ie. not just posts)

  11. Dave  |  October 29th, 2007 at 9:13 pm #

    Dave - Gravatar

    You might find what’s doing it by doing a search inside all of the files in your wp-content directory for (”301″ and “http://www.bloggingtips.com/index.php”). I just looked on Live HTTP headers, and it’s definitely returning a 301 for whatever reason.

    Not that it’s a lot of help, but to let you know it can work: I’m running wp-cache on my blog, with an htaccess that redirects for canonicalization (though, I go for no www instead).

  12. Kevin  |  October 29th, 2007 at 9:47 pm #

    Kevin - Gravatar

    I removed the plugin for now just til I find out whats wrong.

    I think im heading in the right direction though. I removed the redirection from htaccess in my root folder and non www went to www on all wordpress pages but on the forums the redirect wasnt there. Therefore wordpress clearly has a redirection somewhere.

    I just updated to the new version of wordpress the other day. Perhaps wordpress has some sort of redirect feature in it now (longshot).

    p.s. many thanks for all your help :)

  13. Travis  |  October 29th, 2007 at 10:53 pm #

    Travis - Gravatar

    My redirect seems to still be working fine, so it doesn’t look like the update should have affected it (I’m on 2.3.1).

    Good luck getting it figured out!

  14. SarahG  |  October 30th, 2007 at 10:15 am #

    SarahG - Gravatar

    WordPress doesn’t have a redirect, it uses absolute URLs and the main domain URL is the one that is entered under your General Options page. For example if you have http://www.domain.com on this page, then if you visit the site at domain.com, whilst the first page won’t change to the www version of the domain (htaccess interference aside), all of your internal links will have the http://www.domain.com version.

    I’ve just tested this on a site that doesn’t have a htccess (as it’s on IIS) and uses the latest WP version.

    Kevin, if you want I can take a look at the WP Cache plugin and determine where it sets the URLs and for it to add in ‘www’ into it. Perhaps things will work correctly then.

  15. Kevin  |  October 30th, 2007 at 10:19 am #

    Kevin - Gravatar

    That would be great Sarah. From what Dave has said, it seems like a good plugin once you get it working however since adding it my redirect is messed up (I cant be 100% sure it caused the problem but didn’t notice it before)

  16. jai  |  October 30th, 2007 at 10:38 am #

    jai - Gravatar

    It seems WP-cache has a bad bug which freezes your blog.

  17. SarahG  |  October 30th, 2007 at 11:57 am #

    SarahG - Gravatar

    Kevin, I installed the plugin on one of my sites and it’s showing the ‘www’ portion of the domain when I list cached files. I can only assume it’s pulling this from the address set up under my General options page. Is your site URL set up with the ‘www’ part? If so then I’m a bit lost as to why one site does one thing and one does another!

    I’ve looked through the code and can see that the URL is stored in the .meta file for each cached file. This will be the URL that you see listed in your admin page. Looking through the code it simply stores the PHP variable of SERVER_NAME which is a global variable and just grabs the domain part of the address. If this is http://www.domain.com then it will have that in full.

    So what I can only assume is that when your cached files were created, the actual URL being used was the non www version. Strange considering you have htaccess to use the www version.

    At most I could change this variable into a constant of http://www.bloggingtips.com so that it would always have the ‘www’ in it. Just don’t use it on any other domain ;)

    Let me know whether you want to try using it again and I’ll send the file over :)

  18. Kevin  |  October 30th, 2007 at 1:34 pm #

    Kevin - Gravatar

    I definately have www in the options page, always have. I am going to try the plugin again as im sure any problem was just caused by my redirect in my htaccess file however at the moment my main concern is getting the redirect working on the site

    ie. when i remove the redirect code I mentioned from my htaccess file the redirect on wordpress works fine but on the forums it doesnt work. So clearly there is something somewhere which is causing the redirect. I’ll look more into this later and try and fix that. Once I have that I’ll then try the plugin out without a redirect in place and see if that is a problem. Have you tried the plugin without a redirect?

  19. SarahG  |  October 30th, 2007 at 1:46 pm #

    SarahG - Gravatar

    Kevin, yes I used the plugin on a site that doesn’t have any htaccess rules besides permalinks. To be honest I stopped using the htaccess method of control www vs non-www as it interfered with something else last year. I can’t remember what though.

Trackbacks to 'Reduce the server load your wordpress blog creates'

  1. ReviewYou.net » Blog Archive » WP-Cache Review, StumbleUpon Toolbar Review, John Chow Looks At Homes
  2. MYBLOGPOST.COM
  3. Weekly Links - November 2nd << Vandelay Website Design
  4. This Week In SEO - 11/2/07 - TheVanBlog

Leave Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>