In previous post LAMP: Make it faster I described how to make Web application faster by turning on MySQL and PHP cache. New WordPress installation with few modules can give only 3.44 requests per second. After turning on MySQL cache and PHP cache, site becomes 150% quicker. This can be done on MySQL and PHP level. On the other hand if your site is installed on shared host, you probably have restricted access and you can’t edit my.cnf nor install APC. You can only install cache module like WP-Cache is, to improve speed.
- Download and install WP-Cache
- Edit wp-config.php and check directory permissions
1. Download and install Wp-cache
This is pretty easy task. Download wp-cache.zip (file is only 15KB) and unzip it under wp-content/plugins directory. After unzipping, wp-cache directory should appear in plugin directory. Next step is plugin activation in Plugins section of WordPress and plugin enabling in WP-Cache Manager. Go to the WP-Cache Manager and enable WP-Cache (WP-Cache is disabled by default).
2. Edit wp-config.php and check directory permissions
You are almost done. Open wp-config.php file and add define(‘WP_CACHE’, true) line. It’s written in documentation. But you should add it before last line with require_once. Isn’t it obvious!?
# last few lines of wp-config.php file ... ... /* That's all, stop editing! Happy blogging. */ define('ABSPATH', dirname(__FILE__).'/'); define('WP_CACHE', true); # <-- add here require_once(ABSPATH.'wp-settings.php'); # <-- not here
I spend few hours to figure out why WP-Cache is not working. I checked directory permissions on:
And give them 777 but without any luck. In WP-Cache Manager under Cache contents section WP-Cache was saying 0 cached pages and 0 expired pages. I looked into wp-content/cache and the directory was empty. I checked Apache error_log - there was silence. Huh, after careful problem analyse, trick was in line order. Hope this will save your hair. :)
As you can read in my previous article LAMP: Make it faster, WordPress is able to handle 3.44 requests per second. This is really slow. I read about peaks where WordPress article appears on frontpage of digg.com or similar service and Web site became unreachable because of many requests.To survive peaks, Web site should be able to handle hundreds of request per second. And here comes our saviour - WP-Cache. Logic is simple. After first page request, generated HTML and metadata are saved to the wp-content/cache directory. Every other request for the same page uses stored page and return it from the cache. After elapsed expiration time, new content is generated and the old page is replaced. Lets see ab statistics for the new WordPress installation (version 2.5.1) on dual core P4 2.6GHz with 1GB of memory and Linux Fedora Core 9:
Concurrency Level: 10 Time taken for tests: 29.35572 seconds Complete requests: 100 Total transferred: 2134100 bytes HTML transferred: 2114400 bytes Requests per second: 3.44 [num/sec] (mean) Time per request: 2903.557 [ms] (mean) Time per request: 290.356 [ms] (mean, across all concurrent requests) Transfer rate: 71.77 [Kbytes/sec] received
WordPress can serve only 3.44 requests per second. Turn on MySQL and PHP caching:
Concurrency Level: 10 Time taken for tests: 11.653682 seconds Complete requests: 100 Total transferred: 2134100 bytes HTML transferred: 2114400 bytes Requests per second: 8.58 [num/sec] (mean) Time per request: 1165.368 [ms] (mean) Time per request: 116.537 [ms] (mean, across all concurrent requests) Transfer rate: 178.83 [Kbytes/sec] received
Site becomes quicker, but improvement is still insufficient for larger traffic. After WP-Cache installation, test looks excellent:
Concurrency Level: 10 Time taken for tests: 0.214170 seconds Complete requests: 100 Total transferred: 2276986 bytes HTML transferred: 2251228 bytes Requests per second: 466.92 [num/sec] (mean) Time per request: 21.417 [ms] (mean) Time per request: 2.142 [ms] (mean, across all concurrent requests) Transfer rate: 10379.61 [Kbytes/sec] received
As you can see, with WP-Cache, WordPress is able to deliver 467 requests per second and if you compare it with 8.58 this is significant speed-up. But remember that PHP caching (APC) is turned on. I will turn off APC to simulate shared host environment. MySQL caching doesn't matter for this test because WordPress with WP-Cache module will go to the database only first time and all other requests will be served from the cache.
Concurrency Level: 10 Time taken for tests: 0.424646 seconds Complete requests: 100 Total transferred: 2169581 bytes HTML transferred: 2145038 bytes Requests per second: 235.49 [num/sec] (mean) Time per request: 42.465 [ms] (mean) Time per request: 4.246 [ms] (mean, across all concurrent requests) Transfer rate: 4987.68 [Kbytes/sec] received
WP-Cache will not only speed-up your WordPress, but it will also spare CPU usage. That can be very handy if you have CPU quota on shared host. With internal cache module, WordPress will survive peaks and high traffic storms. Cache module is the only way to make WordPress run faster on shared host with restricted access.
4 thoughts on “Make WordPress fly”
Thanks a lot , nice article and it help me to more understand
Thanks, my blog loads a lot faster now thanks to this simple tweak.
Thanks for this, that was really useful for me too.
WP-Cache really helps to reduce load and speeds up WordPress site. All I can say at the end is to recommend its usage.