Performance

What Is PHP OPcache and How Does It Speed Up Your WordPress Site?

by dotCanada Team
What Is PHP OPcache and How Does It Speed Up Your WordPress Site?

If you have looked into WordPress performance optimisation, you have likely encountered recommendations about caching plugins, CDNs, and image optimisation. These are all legitimate improvements. But there is a layer of caching that happens before any of that comes into play, at the PHP interpreter level - and it can have a substantial impact on how fast your WordPress site responds.

Why PHP Is Slow Without Caching

PHP is an interpreted language. Every time your server receives a request for a WordPress page, it needs to:

  1. Read the PHP files from disk
  2. Parse the raw PHP code into a structured representation
  3. Compile that into bytecode (a set of low-level instructions the interpreter can execute)
  4. Execute the bytecode
  5. Return the output

Steps 1 through 3 are identical on every request. Your wp-settings.php, functions.php, and every plugin file have not changed between requests, but the server is parsing and compiling them from scratch every single time. On a busy site, this repeated compilation is a significant and entirely unnecessary overhead.

What OPcache Does

OPcache (Opcode Cache) intercepts the compilation step and stores the resulting bytecode in the server's shared memory. On subsequent requests for the same file, PHP skips the read-parse-compile cycle entirely and goes straight to executing the cached bytecode.

The result is that the CPU time spent on script compilation - which can be substantial on a plugin-heavy WordPress installation - is largely eliminated. Benchmark measurements on typical WordPress sites show improvements in the range of 20 to 40% for admin panel responsiveness and page generation time, with the gains being larger on sites with more plugins (more PHP files to compile).

OPcache is a PHP extension bundled with PHP since version 5.5. It does not require installing anything separately; it just needs to be enabled and configured.

How to Check Whether OPcache Is Enabled

The most direct method is to create a PHP info file on your server. In your public directory, create a file named phpinfo.php containing <?php phpinfo(); ?>. Open it in your browser and search the output for "Opcache." If it appears with a status of "enabled," OPcache is active. Delete the file immediately afterward - leaving a phpinfo page publicly accessible is a security risk.

Through cPanel, you can often check and modify PHP settings under the PHP Selector or MultiPHP INI Editor sections. Look for opcache.enable and confirm it is set to 1.

If you are unsure, your hosting provider's support team can confirm whether OPcache is enabled for your account and help you turn it on if it is not.

OPcache Configuration Worth Knowing

Two settings have the most practical impact:

opcache.memory_consumption sets how much server memory (in megabytes) is allocated for the bytecode cache. The default is often 128MB, which is sufficient for most WordPress installations. Sites with many plugins may benefit from 256MB.

opcache.validate_timestamps controls whether PHP checks whether a file has changed before using the cached version. In production, setting this to 0 (or increasing opcache.revalidate_freq) improves performance - but means cached code is not immediately updated when you change a file. In development environments, keep this at 1 so changes take effect immediately.

After installing or updating a plugin or theme, you may occasionally need to clear the OPcache to ensure the new code is used. Many hosting control panels include an OPcache reset button, or plugins like WP Reset or Cloudflare's WordPress plugin can trigger a cache clear.

PHP Version Matters Too

While you are thinking about PHP performance, the version of PHP you are running is also a significant variable. PHP 8.x introduced a Just-In-Time (JIT) compiler that provides additional performance benefits on top of OPcache, particularly for computation-heavy operations. PHP 8.2 and 8.3 are measurably faster than PHP 7.x on WordPress workloads - performance improvements in the range of 15 to 25% have been consistently reported when upgrading from 7.4 to 8.x.

You can change your PHP version in cPanel under the MultiPHP Manager or PHP Selector section. Before upgrading, confirm that your WordPress version, theme, and all plugins are compatible with the target PHP version. Most actively maintained plugins and themes have supported PHP 8.x for several years now.

Enabling OPcache and running a current PHP version are two of the lowest-effort, highest-impact performance improvements available for a WordPress hosting environment. Neither requires changes to your site's code or content - they are infrastructure-level improvements that make everything else run faster.

100% Satisfaction Guarantee

We're so confident you'll love dotCanada that we offer a 30-day money-back guarantee. Not satisfied? Get a full refund, no questions asked.

Ready to Get Started?

Join thousands of Canadian website owners who trust dotCanada for reliable, fast web hosting.

Get Started Today