If you are on a VPS or a dedicated server, you have some optimization issues to grapple with. Your PHP process can run faster if you set up an opcode cache, which will store byte-compiled PHP files in memory for a while so that your server doesn’t have to recompile them every time it runs them. The default choice for opcode caching (for PHP versions higher than 5.5) is Zend OPCache, which can be compiled in using Easy Apache on your WHM. Or you can get it installed on your server with your friendly hosting provider‘s help.
Another level of caching is for user data. Many apps, mine included, need their data cached for performance purposes. WordPress does too, and uses a Transient API layer to store the temporary data in your database, in the same table as your options (wp_options) with identifiable keys. The default choice for a better performing, memory-based cache used to be APC (Alternative PHP Cache), which used to do both opcode caching and user caching, but is defunct now. But, you can still use the user data caching part of it by installing APCu.
Note that both opcode caching and user data caching make sense only if the PHP process persists over multiple requests. If each request is handled by a newly spawned PHP process, it has no way of taking advantage of any kind of caching. The mode in which your PHP handler operates can be selected using your WHM, typically found under Configure PHP and suEXEC. The per-request spawning will happen if you set your php handler as suPHP. And one persistent mode DSO (Dynamic Shared Object).
After setting up APCu, you will still need to let your WordPress installation know that you have a user data cache, and that there is no need to pollute the wp_options table with transients. You can do this by using the ACPu Object Cache Backend plugin.
To summarize, there are the optimization techniques you will need to undertake:
- Switch to the DSO mode for your PHP handler
- Get Zend OpCache installed.
- Get APCu, and provide it to object-cache.php, for instance.
pecl install channel://pecl.php.net/APCu-4.0.10if you are using PHP5.5. Or
pecl install channel://pecl.php.net/APCu-5.1.2for PHP7. See APCu PECL page for the latest version info.
- Download and copy apc.php (ensure you download the right version) and opcache.php to visualize and optimize the caches.
- Install the ACPu Object Cache Backend plugin for all your WordPress blogs.
As I mentioned earlier, you need to run your PHP handler in DSO mode (or one of the other shared modes) to benefit from caching. One pesky problem I encountered when I switched to DSO was that my scripts could not use
set_include_path(). I will write up the solution in the next article, coming up later this week. Stay tuned.
If you cannot install APCu for whatever reason, it is possible to simulate it. I am developing this simulation, and will release it as a plugin soon. And you will see a write-up about it on this blog. Agin, stay tuned.