WP Super Cache 0.9.7

WP Super Cache version 0.9.7 is now available. WP Super Cache is a page caching plugin for WordPress that will significantly speed up your website.

Since the last release of the plugin a number of new features have been adding, bugs fixed, and documentation updated. For a taster, here are the changes from the readme.txt:

  1. Fixed problem with blogs in folders.
  2. Added cache file listing and delete links to admin page.
  3. Added “Newest Cached Pages” listing in sidebox.
  4. Made admin page translatable. (work in progress)
  5. Added “How do I make certain parts of the page stay dynamic?” to FAQ.
  6. Disable supercaching when GET parameters present instead of disabling all caching. Disable on POST (as normal) and preview.
  7. Fixed problem with cron job and mutex filename.
  8. Warn users they must enable mobile device support if rewrite rules detected. Better detection of when to warn that .htaccess rules must be updated (no need when rewrite rules not present)
  9. Use the wordpress_test_cookie in the cache key.
  10. Show correct number of cache files when compression off.
  11. Fixed problem with PHP safe_mode detection.
  12. Various bugfixes and documentation updates. See Changelog.txt
  13. Advanced: added “late init” feature so that plugin activates on “init”. Set $wp_super_cache_late_init to true in config file to use.
  14. Advanced: Added “wpsupercache_404” filter. Return true to cache 404 error pages.

If you’re upgrading and your blog is installed in a sub directory the mod_rewrite rules may not have been created correctly. You’ll know this because the timestamp on your cached pages will change on every load. If that happens, remove the Supercache rewrite rules and recreate them through the admin page.

wp-super-cache-list

You can list all the blog’s cache files now, ordered by generation time. From that listing you can delete individual files.

wp-super-cache-debug

The debug function is very powerful. You can choose the level of logging. Level 1 logs errors and warnings of a serious nature. Level 5 logs them plus lots of normal functions. Here’s what level 5 logging looks like for one single request:

20:49:34 /was-the-janitor-really-in-the-fugitive/ No wp-cache file exists or user agent rejected.
20:49:35 /was-the-janitor-really-in-the-fugitive/ In WP Cache Phase 2
21:49:35 /was-the-janitor-really-in-the-fugitive/ Setting up WordPress actions
21:49:35 /was-the-janitor-really-in-the-fugitive/ Created output buffer
21:49:35 /was-the-janitor-really-in-the-fugitive/ supercache dir: /www/wp-content/cache/supercache/ocaoimh.ie/was-the-janitor-really-in-the-fugitive/
21:49:35 /was-the-janitor-really-in-the-fugitive/ Output buffer callback
21:49:35 /was-the-janitor-really-in-the-fugitive/ supercache dir: /www/wp-content/cache/supercache/ocaoimh.ie/was-the-janitor-really-in-the-fugitive/
21:49:35 /was-the-janitor-really-in-the-fugitive/ Anonymous user detected. Only creating Supercache file.
21:49:35 /was-the-janitor-really-in-the-fugitive/ Gzipping buffer.
21:49:35 /was-the-janitor-really-in-the-fugitive/ Writing non-gzipped buffer to supercache file.
21:49:35 /was-the-janitor-really-in-the-fugitive/ Writing gzipped buffer to supercache file.
21:49:35 /was-the-janitor-really-in-the-fugitive/ Renamed temp supercache file to /www/wp-content/cache/supercache/ocaoimh.ie/was-the-janitor-really-in-the-fugitive/index.html
21:49:35 /was-the-janitor-really-in-the-fugitive/ Renamed temp supercache gz file to /www/wp-content/cache/supercache/ocaoimh.ie/was-the-janitor-really-in-the-fugitive/index.html.gz
21:49:35 /was-the-janitor-really-in-the-fugitive/ Sending buffer to browser

That’s a lot of text. Keep an eye on the load on your server because logging that much data on a busy server will add extra load. Start by limiting the logging to your own IP and test with various browsers.
The error messages that are normally sent to the browser about “missing html tag”, “404 error” and “blank page” are now only shown if debugging is enabled. This will hopefully avoid problems with PHP scripts that generate Javascript.

This release adds a new “late init” feature. This is only useful in half-on mode however. This causes the plugin to create the “cache key” and display the cached page at the end of the “init” action, after all WordPress include files and plugins have been loaded. This is very useful if your application needs to interrogate the database to modify the cache key. Activate it by setting $wp_super_cache_late_init to true in the config file.

Lots to digest and new toys to try out. Hope you enjoy this new version of the plugin!

Pigs help translate your plugin

I’m in the middle of translating the WP Super Cache plugin (one of my goals before a 1.0 release). The docs make it easy to understand how to do it, but it is such a chore when there is so much text. According to Vim, I’m about 25% of the way through wp-cache.php

Checking to make sure that all the strings are translated is tiresome but the Pig Latin plugin makes it easier to spot untranslatable strings:

supercache1

supercache2

There will be a new release of supercache soon, but check out the download page and grab the development version if you want an exclusive look at the new debugger, “newest cached files” listing and bug fixes.

WP Super Cache 0.9.6.1

WP Super Cache 0.9.6.1 is now available.

This release adds the following menu item to the admin page.

page_types

You can now choose to not cache different types of pages on your blog. Don’t want to cache your front page? That’s easy now. The indented page types are types covered by the top type. “Archives” covers “Tag” and “Category” pages for example.
See the Conditional Tags codex page for a description of the page types, especially “front page” and “home”.

I also fixed a few bugs, including the AYS problem saving posts which was a problem if you had “Don’t cache for logged in users” enabled.

I never got around to blogging about 0.9.6 but that included an uninstall script that deletes the folders and files created by wp-super-cache. Make sure you read the readme.txt before running it. For security reasons you have to edit the script before using it.

I also updated the mod_rewrite rules in cache/.htaccess (Thanks Andrew!) For some reason the web server forgets the mime type it’s supposed to serve gzipped supercache files as. It should be “text/html” in the cache dir but randomly and on the odd occasion it reverts to the gzip mime type. I examined the cache files when this happens and they look correct. Clearing the cache dir fixes the problem temporarily (and file sizes match before and after). I can’t explain it.
Remove cache/.htaccess if you see this happen (you might need to use the uninstall script) and reload the admin page to regenerate the file. The new rules force the mime type in a different way. Hopefully Apache won’t forget it this time.

Go Mobile with Supercache

I’ll be honest, I don’t have much experience with mobile content. I’ve rarely browsed the net on a mobile device. I don’t have an iPhone and don’t intend buying one but lots of people do use mobile devices to browse online.

With that in mind, and after some pestering by Vladimir I modified WP Super Cache so it will support mobile devices and operate in full super caching mode!

The plugin now filters out requests from the most common mobile user agents and serves those requests in “half on” WP-Cache mode while serving the rest of your visitors static html files. As I’ve said many times before, the speed differences between both modes is negligible for normal traffic but it’s a nice safety net in case your site is inundated.

Only thing is, I want people to test it first before making a final release. Grab the development version from the download page and give it a whirl.
Your mod_rewrite rules in the .htaccess file have to be updated but if you delete the “WPSuperCache” rules they can be regenerated by the plugin next time you load the admin page.
There are also a number of other bugfixes and enhancements too so check out the Changelog.txt for more details.

I use WordPress Mobile Edition here and last Sunday I noticed an extra 10,000 requests from Google using odd looking “mobile useragents” like this one:

SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)

The actual mobile device changed but the Google bit stayed the same and all requests came from 66.249.71.2
Eventually I figured out that Google was adding my site to the “mobile” section of their index. Presumably to be served from here. Cool, another way of getting to my site.

PS. the development version also has a small modification to make it go faster by not checking file modification time on each request. This could help on really busy servers.

HOWTO: Make WordPress plugins work with WP Super Cache

Daffodil, snow and water droplets Thaya Kareeson has written an excellent article for plugin developers. It goes through how to make plugins work with WP Super Cache by using dynamic AJAX calls.

WP Super Cache can make static html copies of pages served by WordPress which is great for performance. Unfortunately that means some plugins don’t work because they rely on executing PHP on each request. The plugins need to be rewritten to use AJAX calls by the visitor’s browser. There’s a FAQ in the readme.txt all about it!

I previously wrote about adding AJAX to WordPress plugins but Thaya has worked through a simple example that will work perfectly with WP Super Cache. It’s a good foundation for plugin developers start from.

He also has versions of WP Postviews and Popularity Contest that have been rewritten to support static caching. I haven’t tried either plugin so leave a comment on his blog if you need help!

If you depend on a large portion of your content being dynamic this isn’t the solution for you as it will affect what search engines see. Those bots don’t speak Javascript, but for interactive purposes (ratings, stats etc) it’s the job.

reading glasses Further reading:

  • AJAX in Plugins is a must-read starting point for developers.
  • wp_enqueue_script() is the command WordPress uses to load Javascript files. That page links to a couple of good pages too including this best practices post. As of this writing, Thaya’s example don’t use wp_enqueue_script() but it’s simple to use.

The vast majority of plugins work just fine with WP Super Cache, but some of the ones that don’t are quite popular. If your favourite plugin doesn’t work, why don’t you help the author out and fix it? You have all the source code after all and you’ll be helping everyone else who uses the plugin!

WP Super Cache 0.9.1

WP Super Cache version 0.9.1 is now available. WP Super Cache is a page caching plugin for WordPress that will significantly speed up your website.

Major changes under the hood in this release, and many bugfixes:

  • If your blog is installed in a folder then compare the mod_rewrite rules in your .htaccess with those on the admin page. I fixed a bug in how those are generated.
  • Out goes the shutdown function the plugin relied on for years (going back to the days of wp-cache), and in comes plain old output buffering on it’s own.
  • If you’ve had problems clearing the cache on your blog it could be because wp-cron isn’t firing. I’ve added checks for that. Joost helped me debug that and he blogged about it too. You’ll get a nice warning message if those checks fail.
  • If after all that, your cache still doesn’t clear, add $wp_cache_shutdown_gc = 1; to wp-content/wp-cache-config.php to clear the cache at the end of pageload instead of by wp-cron. It will slow down page generation for a tiny number of your users though.
  • The Last and Next garbage collection times are now in the timezone selected for your blog.
  • Added an admin notice on the plugin page to warn that caching has to be enabled. A warning is shown below the plugin activation row too.
  • If your site runs on a Windows server, I fixed a small problem with slashes and creating the config file.
  • The plugin created empty supercache folders, but that’s fixed now.
  • Bad Behaviour support seems to work nicely now!
  • You can now relocate the supercache plugins folder. See $wp_cache_plugins_dir in wp-cache-config-sample.php.
  • I added 2 new filters: wp_cache_served_cache_file in wp-cache-phase1.php (BB uses this) and wp_cache_file_contents in wp-cache-phase2.php where you can filter the contents of the newly created cache before it’s written out to a file.
  • The readme.txt has been updated too warning about using NFS to store the cache folder, solving wp-cron problems, added the list of Apache modules required for expired pages to really expire in the browser cache.

I also added a donation link in the readme.txt and on the admin page. You can hide it with the click of a button but if you’re feeling generous, I’d appreciate a donation.
I don’t expect many donations, that’s how these things work, but if you tell me your site does 100,000 page views a day and you couldn’t live without caching I might be slightly annoyed if you come looking for free support.

PS. Looks like Bad Behavior support is broken because the docs on the BB site were a little misleading and I don’t use the plugin. Grab badbehaviour.php and copy into plugins/wp-super-cache/plugins/ overwriting the file of the same name in that folder.

Want to test the new WP Super Cache?

I need testers. Several people answered my call on Twitter last week to help test WP Super Cache. Here’s your chance!

Grab the development version and install it in your plugins folder as normal. Some of the new features and bugfixes to look out for:

  • If your cache files aren’t being deleted add “$wp_cache_shutdown_gc = 1;” to the config file, wp-content/wp-cache-config.php. The plugin will do garbage collection at the end of page load instead of using WP Cron. It’ll only fire off as often as before.
  • Empty supercache directories won’t be created now.
  • Bad Behaviour supported is added. Just enable the plugin at the bottom of the admin page.
  • If you’re getting an error “Call to a member function get() on a non-object in .. cache.php” that should be fixed.
  • Incorrect supercache mod_rewrite rules were generated if your blog was installed in a sub directory and they’re fixed now as well but you’ll have to delete the old rules.

If all goes well, WP Super Cache 0.9.1 will be released before the end of the week!

WP Super Cache 0.9

WP Super Cache version 0.9 is now available. WP Super Cache is a page caching plugin for WordPress that will significantly speed up your website.

Update – if your blog is installed in a sub directory instead of at the root of your server, the .htaccess file might be wrong. Download and install the development version which corrects this. You’ll have to edit the .htaccess file (anyone want to volunteer to write an auto-upgrader?) and remove the rules between the lines # BEGIN WPSuperCache and # END WPSuperCache. Delete those lines too and visit your admin page. The plugin should do it’s stuff and spit out correct mod_rewrite rules for you. The dev version also has a few other bug fixes so if you’re adventurous have fun upgrading!
There’s no need to touch wp-content/cache/.htaccess

Are we nearing version 1? Possibly. In this release a number of bugs have been fixed and the following new features added:

  1. Mobile user agents are detected and a different cache page created for them. If you use a plugin that displays a different theme to these devices it will hopefully work now. The plugin changes to “half-on” mode because the detection is done by PHP. Thanks to Alex King‘s WordPress Mobile Edition plugin for the detection code.
  2. The number of cache files will be more than halved on a normal site with plenty of anonymous visitors. This should be a huge win for WordPress MU sites and very busy blogs.
  3. The last and next garbage collection times are displayed on the admin page now.
  4. In previous versions the newly generated page was delivered uncompressed to the first visitor even if the browser supported compression. I’ve fixed this but I’m not 100% certain it will work for everyone so it’s disabled by default. Edit wp-content/wp-cache-config.php and add “$wp_cache_gzip_first = 1;” to enable this. It’s enabled here.
  5. If expiry time is longer than 30 minutes, garbage collection will be done every 10 minutes, else it’ll be done 10 seconds after the expiry time.
cache-contents

Unfortunately wp-content/advanced-cache.php will have to be updated again and it’s not as simple as copying the file from the plugin directory. Full instructions are printed on the admin page and it should auto update in most cases.

PS. Test your upgraded blog on Is my blog working, a project by fellow Automattican Alex Shiels.
Here’s the page for this site. 102ms page generation time is rather fast!

WP Super Cache 0.8.9

WP Super Cache version 0.8.9 is now available. WP Super Cache is a page caching plugin for WordPress that will significantly speed up your website.

This version fixes a number of bugs and adds two new features, but in case you run into problems upgrading, make sure you delete wp-content/advanced-cache.php before copying plugins/wp-super-cache/advanced-cache.php over it. Go on, read that again. Delete that file. Jonathan Dingman didn’t and when he copied the file over the symlink he overwrote wp-super-cache/wp-cache-phase1.php. His site went belly up and he started screaming for my head!!! Err no, he appeared on asking why it didn’t work. Thanks Jonathan for working through the problem with me. My fault for not making the instructions clearer!

If this happens to you, take a deep breath and unzip the plugin again in the plugins folder and delete wp-content/advanced-cache.php

Anyway, the new features are:

  1. Cache rebuild. Serve a static cache file to anonymous users while that file is being generated.
  2. Disable the large global lock that makes every access to the cache atomic.

Besides those, I got rid of the symlinked file in wp-content/, and the plugin now copies a file called “advanced-cache.php” from the plugin directory to simplify things. Especially on operating systems where symlink isn’t available. Yes, that’s Windows.

If your site is horrendously busy and you get a ton of comments every day and you’re too broke to buy a new server, then the cache rebuild feature will help you a lot. You should see the load on your server go way down if you enable this. Anonymous users who visit a page where a comment has just been left will be served a static cache file from the supercache instead of all the requests trying to generate a brand new page. The page served to them might be a few seconds out of date but that trade off is worth it.
Here’s the original thread that inspired the idea. Thanks Tigertech for writing the patch and for sharing the performance graphs. Check out the load on his server, before and after the rebuild function was switch on:

wp super cache load graph

If you’ve had problems with deleting the cache on your blog it *might* be because of file locks. Some hosts just have problems with them. The file locking in the plugin is very coarse. When the plugin wants to do any sort of write operation it grabs a lock, does the writes (which could include clearing expired files, or creating wp-cache and supercache cache files), and then releases the lock.
Any other process running the plugin that tries that won’t get a lock: new cache files won’t be created, and cache files won’t be cleared.
It isn’t a huge problem that the lock is so coarse because the writes don’t take very long (the lock is enabled after the page is generated), but some very busy sites take quite a while to clear their cache files.
On the downside, disabling the file lock won’t stop multiple cached files being generated simultaneously (great), but it also won’t stop multiple “clear cache” attempts either (boo!)
From what I recall of looking at the other cache plugins for WordPress, most of them don’t have any file locking and seem to do just fine.

I almost forgot! There is also a new debug mode. Edit wp-content/wp-cache-config.php and look for “$wp_cache_debug” and follow the instructions. It will send you a few emails when things don’t go right and may help track down any problems.

As a final note, I would like to sincerely thank Robert Wolf who spruced up the admin page and gave it a nice lick of paint and Michael Torbert for helping me debug the plugin a while back.