If you are suddenly receiving a lot of request within a short period of time because you’ve been linked by a large site like Digg or Slashdot, your hosting solution might not be able to handle the load.
This article should help your to prepare your WordPress blog for such a case or if you’re just using a slow webhost and want to improve the general performance.
Note that your room for maneuver is limited in most shared-hosting environments, so you won’t be able to implement all possible options with a $2.95 hosting account.
On the whole there are two areas where we can try to save processing time by caching frequently loaded data. The first one is the server system like the web- and database-server software, the second one is the application (WordPress) itself.
MySQL Query Cache
Since WordPress uses MySQL, almost every page load results in various MySQL queries for logins, post content, categories and so on. It is very likely that this data didn’t change since the last request so we begin with enabling the cache within the MySQL server. Basically, all you need to to is to activate it in the my.cnf (or my.ini) MySQL configuration file with setting the query-cache-type variable to 1. The query-cache-size variable is the size of the query cache in MB, for example 20M. To change the MySQL configuration file, you’ll probably need root access which won’t be available on shared hosts. More info about query cache is available on techiecorner.com and the MySQL Performance blog.
PHP Compiler Cache
WordPress is a PHP application so every request results in a call from the webserver (like Apache) to the PHP interpreter. This program reads the script files and compiles them into opcode which can be executed. This process may need some time, depending on the size of your script. A PHP Compiler cache saves the script in the compiled state in the memory which allows the PHP engine to execute it directly without compiling again which makes the execution about three times faster. Wide known PHP compiler caches are APC and eAccelerator. Please refer to their websites on how to install them, you will also need root access for that.
WordPress Internal Caching
In case of a slow database server, it might be a good idea to store frequently used data in a serialized form on disk. WordPress has an integrated disk-cache which stores rarely changing data like categories and users in a special folder. Note that this cache is not recommended if the disk is slow or your host (like DreamHost) set up a NFS based storage solution which would request the cached data from a remote storage server. To enable WordPress’s internal caching, uncomment or add this to your wp-config.php: define( ‘ENABLE_CACHE’, true ); and make sure that the wp-content/cache folder is writable!
If all the other caching methods are not enough or you can’t apply them, there is a last solution: Caching the complete generated pages. This can be done via an excellent plugin called WP-Cache. The plugin will cache the whole generated page on the disk and skip the complete WordPress execution on further requests. After a specified time or if you publish a new post, the cache will be cleared and generated once again. This method is the fastest available, but it will break some functionality like plugins which add dynamic content to your blog or count page impressions since they are executed only once. Note: If you want to use this plugin and the PHP Compiler Cache APC together, have a look at this posting from Mark Jaquith.
And of course…
Use the current WordPress version
Yes, update to the latest available WordPress version. Using always the most stable release gives you new newest features, security fixes and performance optimizations.
Disable unused plugins
Open your plugin management page and check if you really need all installed plugins. Did you in install some of them just for testing purposes or is their functionality already included in the latest WordPress version? Deactivate them to speed up PHP parsing and processing time.
Optimize your theme
Other hints like reducing HTTP requests, compression and so on can be found on the blog of Paul Stamatiou.