WordPress Performance
If you're serving a busy site using WordPress, you should pay attention to how quickly your copy of WordPress runs. By spending a little time “tweaking” WordPress, you can dramatically affect how fast it runs (and therefore how many visitors it can handle).
This page describes techniques for speeding up WordPress, including FastCGI and WP Super Cache. To show you what a difference these can make, here are some rough performance testing results on our servers for an “out of the box” WordPress installation:
- Standard WordPress installation: 2 page views per second
- WordPress with FastCGI enabled: 8 page views per second
- WordPress with WP Super Cache enabled: 350 or more page views per second for cached files
In other words, using these techniques allows your site to handle well over 200 times as many visitors per second.
To get the full benefit, you do need both FastCGI and WP Super Cache. That's because WP Super Cache only speeds up “cached” pages, and pages won't always be cached. If they aren't cached, they load at the slower speed of either 2 or 8 per second, and you definitely want that to be as fast as possible.
On this page:
- Enabling FastCGI
- Enabling WP Super Cache
- Using WP Super Cache with a subdomain
- Enabling WP Super Cache using a domain name alias
- Avoid slow plugins, especially “WP Spam Free”
- Avoid unnecessary plugins
- Use a "favicon.ico" and "robots.txt" file
- Use WP Tuner to find performance problems
- What about W3 Total Cache?
- Can all this really help that much in the "real world"?
Enabling FastCGI
Using FastCGI for PHP scripts allows the script to stay preloaded in memory, waiting for a page request. This eliminates the normal PHP startup time (which can be as much as half a second per request).
We have detailed technical instructions about enabling FastCGI for your account on our FastCGI page, but note that you don't need to do it yourself: just contact us and we'll be glad to do it for you at no charge.
Enabling WP Super Cache
WP Super Cache is a WordPress plugin. It can be downloaded from the WordPress plugins page (click “Download” on that page), then configured according to the instructions you see when clicking “Installation” on that page.
We'll be glad to install WP Super Cache for you, at no charge, on any copy of WordPress. Just contact us. You'll need to create a temporary administrative user in WordPress (and tell us that username and password) so we can login and configure it for you.
If you get an error message when you activate WP Super Cache, saying that "Mod Rewrite rules cannot be updated" because of missing "BEGIN and END markers" in a .htaccess file, you can easily fix this. Choose Settings > Permalinks in the WordPress admin screens, make sure anything except "Default" is chosen, then Save Changes (even if you don't actually make any changes). This creates the file (if necessary) and adds the correct markers. The WP Super Cache Manager should then be able to update the .htaccess file.
By the way, some versions of WP Super Cache may display warnings on the plugin settings page saying that "wp-content is writeable" or that the path to your blog directory is writable, suggesting you use "chmod 755" to fix it. If you get this message, you should check the directory permissions and fix them if necessary. However, you will probably discover that the directories already have 755 permissions, in which case you can simply ignore the warning.
When you configure the WP Super Cache settings, do not check the box marked “Clear all cache files when a post or page is published. (This may significantly slow down saving of posts.)”. Using that checkbox is not necessary and effectively disables WP Super Cache for a few minutes every time you create a new post.
You should also change the "Expire time" (in the "Expiry Time & Garbage Collection" section) from 3600 to 172800 seconds. Do this even though the WP Super Cache instructions suggest the opposite, for the reasons explained in this blog post.
Using WP Super Cache with a subdomain
If your WordPress site is on a subdomain like "blog.example.com" (instead of at the top level of your Web site), you'll need to change two lines that WP Super Cache adds to your .htaccess file. Specifically, after each "%{DOCUMENT_ROOT}/", you'll need to add your subdirectory to the path.
So if your blog is at "blog.example.com", you'd change "%{DOCUMENT_ROOT}/" to "%{DOCUMENT_ROOT}/blog/". These two lines:
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
Would become:
RewriteCond %{DOCUMENT_ROOT}/blog/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
RewriteCond %{DOCUMENT_ROOT}/blog/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
Again, we'll be glad to do this for you if you have any trouble.
Enabling WP Super Cache using a domain name alias
If you try enabling WP Super Cache using a URL that's a domain name alias, four of the lines that WP Super Cache adds to your .htaccess file may be incorrect. This is caused by a WP Super Cache bug.
Specifically, if your .htaccess file contains "/var/www/html/ex/example.com" in the RewriteCond and RewriteRule lines that were added, that extra text is wrong and should be removed. We can help you troubleshoot and fix this problem if you contact us.
Avoid slow plugins, especially “WP Spam Free”
The idea of WP Super Cache is that for most requests, there is no PHP code that needs to be executed on the server.
However, a small number of WordPress plugins add JavaScript that loads an extra non-cached PHP script for each page view. This defeats the purpose of WP Super Cache.
We strongly recommend avoiding plugins that operate this way. Some that we know of are WP Spam Free, WP Ajax Edit Comments and Featured Content Gallery. (The reCAPTCHA WordPress Plugin is a good alternative to WP Spam Free.)
In addition, you should not use any plugin that contains this line of PHP code:
$wp_rewrite->flush_rules
This causes (potentially large) MySQL database updates for every page viewed, slowing down WordPress dramatically. One such plugin is Sitemap Generator For WordPress MU.
Avoid unnecessary plugins
Every plugin you enable makes WordPress a little slower. Some resource-intensive plugins make WordPress much slower.
We never hear complaints about the speed of WordPress sites that don't use many plugins. Speed only becomes a problem when sites use lots of plugins. We've seen several sites that run more than ten times slower than a standard WordPress installation because of the plugins they use.
If you care about the speed of your site, don't use plugins you don't need, and test every plugin individually to see how much it slows down your site.
Use a "favicon.ico" and "robots.txt" file
If a visitor requests a file that doesn't exist, WordPress displays a useful "file not found" page that includes similar pages, links, and so on. However, that page takes time to generate.
In some cases, it's normal for a file to not exist. In particular, many browsers and search engines request files named "favicon.ico" and "robots.txt".
When those files don't exist, the Web browser or search engine still works properly, so the missing files don't cause visible problems. However, these requests use valuable WordPress processing power to construct the custom "file not found" page, and that effort is completely wasted: no human ever sees the page WordPress creates.
The best and simplest solution is to make sure these two files aren't missing. Create a "favicon.ico" file and add a "robots.txt" file. The robots.txt file can be completely empty if you want.
Alternately, you may want to add this line to your .htaccess file, just before the existing WordPress "RewriteCond %{REQUEST_FILENAME} !-f" line:
RewriteCond %{REQUEST_URI} !^/(crossdomain.xml|favicon.ico|robots.txt)$
That line prevents the custom WordPress 404 PHP code from running when several common "non-human" requests are made for missing files.
Use WP Tuner to find performance problems
If your site is slow, try installing the WP Tuner plugin to get detailed statistics about your WordPress installation. Among other things, it can show you which plugins are slowing down your site.
What about W3 Total Cache?
"W3 Total Cache" is a plugin that claims to do the same thing as WP Super Cache. However, we've found that it's harder to use and often doesn't give the same performance. Stick with WP Super Cache unless you have a very good reason to switch.
Can all this really help that much in the "real world"?
Yes. We have several customers using FastCGI and WP Super Cache who have easily “survived” having their WordPress site listed on the Digg home page, with sustained page view rates of 20-30 pages per second for several hours, even on our most basic Web hosting plan.
Advanced users can use the shell command line to test their own results with the ApacheBench program. Here's a real result from our own blog with WP Super Cache installed:
$ /usr/sbin/ab -n 40 -c 4 http://blog.tigertech.net/ Concurrency Level: 4 Time taken for tests: 0.31100 seconds Complete requests: 40 Failed requests: 0 Write errors: 0 Total transferred: 1849520 bytes HTML transferred: 1836800 bytes Requests per second: 1286.17 [#/sec] (mean) Time per request: 3.110 [ ms ] (mean) Time per request: 0.777 [ ms ] (mean, across all concurrent requests)
In this case, our servers delivered over 1200 page views per second. Real world results won't be that fast because of networking overhead, but it does show that the WordPress software is not a bottleneck at all in this situation.
