Caching WordPress with WP-Cache in a spam filled world

WP-Cache and spam. Who’d have thought they were related? Unfortunately they are because when your blog is spammed WP-Cache doesn’t check if the comment is legitimate or not and deletes cached files related to the spammed post.

I noticed this happened a lot on In Photos.org after I added thumbnails to the top of the page. The thumbnails change when the page is regenerated but I noticed that they would change much more frequently than expected. After some debugging I realised that comment spam was invalidating the WP-Cache cache.

How do you fix this? Here’s a small patch that can be applied to wp-cache-phase2.php, version 2.0.19 (and probably lower) that checks if the submitted comment was moderated or not. You’ll also find wp-cache-phase2.txt below. Just rename that to .php and copy it into your plugins/wp-cache/ folder for it to work.

Remember to update WP-Cache too. Despite last year’s date on the above post, it was updated as recently as last month!

Download

  1. wp-cache-phase2.diff
  2. wp-cache-phase2.txt

Patch will be on it’s way to gallir in a few moments but if you’re using WP-Cache this could be a big help to your site. (and if you use Ultimate Tag Warrior I hope you’re using my patch?)

Ray & Jenny, Pat, and Pamela – thanks!

analytics-nov-27.jpg

Yesterday’s announcement, the fiasco on the Late Late Show on Friday night and now Pamela Anderson’s divorce drove a lot of traffic yesterday. (People started looking for her video again!) As you can see from the Google Analytics graph, soon after 8am in the morning the flood started after Ian Dempsey mentioned the birth.

I took the opportunity to move In Photos to a new Xen server on Xen Planet for a short test period. If you see posts there without the comments form you’re looking at the old site and your DNS hasn’t updated yet. It should be complete in a few hours. The new site is a 64MB xen server and it’s holding up well. I’m toying with the idea of using Lighttpd, especially as a lot of thumbnails will be served from that host but I won’t have time to work on that until the weekend. Every night this week is already booked up with one thing or another.

In other news, moving a WordPress site to a new host is fairly painless!

BarCamp in the Sunny South East

News from Keith is that plans are underway for a BarCamp to be held in Waterford sometime early in the new year. After their positive experience at the BarCamp in Cork, he and Tom Corcoran are planning it, and they can make available, “the facilities of the WIT centre in Carriganore – a superb building situated on its own campus.” Sounds good!

Plans are at an early stage yet, but I think I’ll be able to make the drive there for the day. I haven’t been to Waterford in ages and it’ll be nice to see the place again. Would anyone like to hear about WordPress, WordPress MU or WordPress.com? I’m not saying I will, but maybe …

Check out the Wiki too. That will probably have the most up to date information.

Jason's Custom CSS for WordPress MU

Many moons ago, Jason’s Customciser was released onto an unsuspecting WPMU forum. It’s a small plugin that allowed one to change the value of some of the CSS elements in a theme’s style sheet.

Before you get too excited, it’s in rather a raw format, can cause problems and needs work to be usable. The original plugin used some PHP5 conventions and functions which limited the audience who could use it. I’m posting this because people are wondering where the PHP4 port I wrote disappeared to. It’s still here, but please link to this post instead of linking to the zip file.

Download Jason’s Customciser-doc – this plugin needs a lot of work to be usable. I’m not joking!

If you’re wondering, this is not the same plugin that is used on WordPress.com to allow editing of CSS files. I just wonder why someone doesn’t write a simple templating system in Smarty or something that loads through the traditional WordPress theme files? It’s a no-brainer. It may not be the most efficient way of doing it, but it’s one simple way.

Brians Latest Comments Cached

After the success I had with Ultimate Tag Warrior I turned my eye to another popular WordPress plugin that I use: Brian’s Latest Comments.

This plugin lists the latest comments on your blog and I wanted to squeeze every bit of performance out of my server so I guessed that caching the output of the plugin would save several queries for every page generation. Comments are cached for an hour. The cache isn’t invalidated by a new comment so don’t worry if the comments list doesn’t update immediately after a comment is made.

Install

I used the same cache directory that WP Cache 2.0 uses, wp-content/cache/. You’ll have to create that directory and make sure the webserver can write to it. The simplest way of doing that is by running the command chmod 777 cache. Download the file below and copy it into your plugins directory. If you’ve never installed the original plugin you’ll need to download it and read the install.txt to find out how to use the plugin.

Download

brianslatestcomments.txt – rename to .php and copy into your plugins directory.

The Schneider Interview

Robert Scoble talks to Toni Schneider, the CEO of Automattic in this video interview about WordPress.com, Automattic and lots of other stuff. I’ve only watched the first 10 minutes, Toni talks about some of the features of WordPress.com – paid features, making money, adverts, fighting splogs and more.

Do you like Akismet? That’s covered too. Make sure you set aside some time today to watch this interview if you use WordPress!

Ping Google Too!

Google announced that they will accept pings to their blogsearch service. Hopefully Pingomatic will support it soon so you don’t need to update your “Update Services” in WordPress. I’d say Matt’s sleeping off the jet lag from his trip to Vienna but it’ll probably be there in a few hours!

If you can’t wait, add “http://blogsearch.google.com/ping/RPC2” to the “Update Services” in your WordPress Dashboard under Options->Writing.

Why is this good? By pinging Google you can tell them that you have updated your blog. That will get your post into the Google Blog Search index that much faster.

Update! Matt has already updated Pingomatic. WordPress users can rest easy that their posts will show up quickly on Google Blog Search now!

Killing off PHP

Do you know why Apache processes get stuck and stop responding when serving pages on a WordPress site?

I’ve seen this happen here and on my previous host on a regular basis. I don’t know what happens. It can’t be a PHP script gone into an infinite loop because the normal Apache timeout should kill it. It’s not MySQL as a quick inspection of the process list usually shows it’s empty.

It could be plugins, some of them haven’t been written to the high standards that is expected in WordPress core. It could be some strange interaction between plugins and core code and memory limits and PHP extensions.

Whatever causes it, this will fix it. It’s brutal, it’s crude, but it’ll stop the load average going up on your box and it will ensure that every Apache child process is listening and responding. Add this to the crontab of your nobody or www-data user. Pick whichever user runs the webserver because you want to limit the damage in case something bad happens and the command malfunctions!
*/10 * * * * ps auxw|grep apache2| awk '$10 !~ /0:00/ {print $2":"$10}'|awk -F ':' '$2 !~ 0 {print $1}'|xargs kill -9 2> /dev/null
What this does is it uses the ps, grep, and awk tools to find processes that are using anything more than the minimum CPU time. It is very crude, but it works.

If you use Litespeed, then replace “apache2” with “lsphp”. I have found that this is very necessary as those processes get stuck quite often, especially in low memory situations.