How PHP OPcache Makes WordPress Faster and More Reliable
Image
When people talk about speeding up WordPress, they usually mean caching pages, images or database queries. But one of the biggest performance levers sits one layer deeper: PHP OPcache. For modern WordPress sites – especially those running complex plugins, custom themes or headless frontends – OPcache is the difference between a server that thrashes under load and one that stays predictable and fast.
In this post, we’ll break down how PHP OPcache works in WordPress, why it matters for performance and reliability and how to verify it’s actually working on your site.
Important note: On managed platforms like Pantheon, OPcache is handled automatically, so you don’t need to worry about it at all. It’s flushed on every code deploy and isn’t something customers need (or are able) to manually clear.
What is PHP OPcache in WordPress and why does it matter for WordPress performance?
PHP OPcache is a server-level bytecode cache built directly into PHP that dramatically changes how WordPress code is executed. Normally, every request to a WordPress page forces PHP to read every needed file from disk, parse the source code and compile it into executable bytecode before it can run. That compilation work happens over and over again, even though the code itself hasn’t changed.
OPcache removes that waste. It compiles WordPress core, theme files and plugin code once, stores the resulting bytecode in shared memory and serves that same precompiled code to every visitor. Instead of constantly hitting the filesystem and CPU to rebuild PHP scripts, WordPress can execute already-compiled instructions directly from memory. The result is far lower server overhead and much faster time to first byte (TTFB).
Properly configured OPcache typically delivers faster page loads and allows servers to handle more requests per second without adding hardware. On plugin-heavy sites like WooCommerce or large Multisite networks, the gains are even more pronounced because OPcache eliminates repeated compilation across tens of thousands of PHP files.
This makes OPcache fundamentally different from page caching or content delivery network (CDN) layers. It accelerates every WordPress request – logged-in users, API calls, admin pages, background jobs – by speeding up the PHP engine itself.
It’s also important to know that how OPcache is configured or whether you configure it at all depends entirely on your hosting model. On self-hosted WordPress environments, OPcache is something operators explicitly size, tune and monitor. On managed WordPress platforms such as Pantheon, OPcache is part of the underlying PHP runtime and is handled for you – you don’t need to worry about it.
How PHP OPcache Works in WordPress
On a standard request, PHP has to read every needed file from disk, parse the source code, compile it into low-level bytecode and only then execute it. WordPress may load hundreds of PHP files per page request, depending on active plugins and theme complexity, which is why PHP execution becomes a major performance bottleneck at scale.
OPcache changes that workflow by inserting itself into the compilation step. The first time a PHP file is executed, OPcache allows PHP to parse and compile it as usual, then stores the resulting bytecode in a shared memory pool. That bytecode is indexed by the file path and metadata, so it can be retrieved instantly later. On subsequent requests, PHP skips parsing and compilation entirely and executes the already-compiled code straight from memory. Three of the four execution stages disappear, saving CPU time and filesystem I/O on every hit.
This is why OPcache delivers real-world performance gains for WordPress even before page caching or CDNs come into play.
OPcache manages three key memory areas that determine how well it works for WordPress:
- The main opcode memory stores the compiled PHP instructions themselves.
- The interned strings buffer deduplicates repeated strings used across WordPress core and plugins, dramatically reducing memory usage.
- A hash table tracks file paths and metadata, which limits how many PHP files OPcache can cache at once – an important setting for plugin-heavy or multisite installs.
OPcache also needs a way to know when files change. With timestamp validation enabled, it periodically checks whether a PHP file has been modified and recompiles it if needed. In production environments with controlled deployments, many hosts disable these checks and clear OPcache manually after releases to eliminate filesystem overhead. In WordPress sites that rely on plugin and theme updates from the admin UI, short revalidation intervals strike a balance between freshness and performance.
Because WordPress frequently updates files, OPcache can accumulate “wasted” memory from old compiled scripts. If memory or file limits are too small, OPcache may stop caching new files and recompile uncached scripts on every request, causing severe performance degradation. This is why proper sizing and monitoring are critical – a healthy WordPress OPcache should show a 98%+ hit rate, low wasted memory and enough capacity to store every PHP file the site uses.
Do you need to install or enable OPcache?
In most WordPress environments today, you don’t need to manually install PHP OPcache at all. OPcache has been bundled with PHP since version 5.5.
If you’re on PHP 8.5 or later, OPcache is no longer optional. It’s compiled into every PHP binary and enabled by default. On PHP 5.5 to 8.4, OPcache is still bundled with PHP, but may require explicit activation in php.ini if your host hasn’t enabled it.
For most WordPress users, hosting makes this a non-issue. Managed platforms like Pantheon, Kinsta and WP Engine enable and tune OPcache automatically as part of their PHP stack. You don’t install it, toggle it or manage its configuration. Those concerns are handled entirely by the platform as part of the PHP runtime. In these environments, manual OPcache flushing is neither necessary nor available – and attempting to do so is outside the supported workflow.
You typically only need to think about OPcache if you’re self-hosting on a VPS, dedicated server or basic shared hosting. In those cases, OPcache is usually already installed but may need to be enabled in PHP-FPM or Apache configuration. Truly manual installation is rare and usually limited to legacy or highly customized PHP builds.
How to check if OPcache is active on your WordPress site
There are several reliable ways to confirm whether PHP OPcache is running on your WordPress site. The most comprehensive option is phpinfo():
- Create a temporary phpinfo.php file in your WordPress root containing:
<?php phpinfo(); ?>
- Load it in your browser and search for Zend OPcache. If OPcache is active, you’ll see a dedicated section showing ‘opcache.enable = On’, along with memory usage, cached scripts and hit statistics.
- Delete the file immediately after checking, as it exposes sensitive server details.
For a safer, WordPress-native approach, install a plugin such as OPcache Manager or WP OPcache. These surface OPcache status, hit rate, memory usage and cached file counts directly in the admin dashboard. Be aware that on some shared hosts, OPcache metrics may be hidden even if OPcache itself is active.
Developers and operators can check programmatically using opcache_get_status() or via WP-CLI, provided ‘opcache.enable_cli=1’ is set. Command-line checks are especially useful for validating background jobs and cron performance.
On managed platforms like Pantheon, Kinsta and WP Engine, OPcache is enabled by default. In those environments, verification is mainly useful for monitoring and not troubleshooting availability.
If OPcache is active, what comes next depends on your hosting model. On managed platforms like Pantheon, OPcache sizing, behavior and lifecycle are handled by the platform and don’t require user intervention. On the other hand, in self-hosted or shared environments, verification is the first step before tuning memory limits or file counts.
Why OPcache might not be working on your WordPress site
When OPcache behaves unexpectedly, the underlying cause often depends on whether the site is self-hosted or running on a managed platform. If you’re self-hosting or using shared environments, it’s the result of hosting constraints, security hardening or an undersized configuration that limits its effectiveness:
- Disabled monitoring functions: Hosts often block opcache_get_status() and opcache_reset() to prevent users from inspecting or clearing server-wide caches. In these cases, OPcache still accelerates PHP execution, but WordPress plugins can’t display metrics, leading to misleading “OPcache not active” warnings.
- Resource limits: The default 128MB memory allocation and low file limits are insufficient for modern WordPress sites with large plugin stacks or WooCommerce. When OPcache runs out of memory or file slots, it silently stops caching new scripts, causing sudden TTFB spikes and inconsistent performance.
- Automatic updates: If OPcache serves stale bytecode during a plugin or core update, brief but serious fatal errors can occur unless timestamp validation or cache resets are handled correctly.
On managed platforms like Pantheon, OPcache issues are rarely the result of missing configuration or manual cache handling. When problems do occur, they are typically caused by plugins or workflows that bypass the platform’s deployment model, rather than something the customer failed to configure.
On Pantheon, customers are not expected to reset or flush OPcache themselves. These risks are mitigated through containerized infrastructure, controlled deployments and platform-level cache invalidation for object and page caching layers. PHP-FPM pool recycling during code deployments ensures stale OPcache bytecode is cleared, while appropriate OPcache memory allocation and monitoring eliminate the resource exhaustion issues common on shared hosting.
The OPcache settings that actually matter for WordPress
OPcache delivers outsized performance gains for WordPress, but only a small subset of settings actually matters. The rest are legacy knobs, marginal tweaks or outright distractions. If you focus on the right ones, you’ll see real, measurable improvements in PHP execution time and stability.
The four settings that do the heavy lifting are:
opcache.enable
opcache.enable is the master switch. It should always be enabled in production. There’s no valid performance or compatibility reason to turn OPcache off on modern WordPress sites.
opcache.memory_consumption
opcache.memory_consumption controls how much shared memory OPcache has for compiled PHP code. The default 128MB is too small for most sites:
- 128MB is s a standard starting point for small sites, but 256MB is recommended.
- 256 to 384MB is recommended for medium sites (with 10-20 plugins).
- 384 to 512MB+ is recommended for WooCommerce, Multisite and plugin-heavy installs.
If this value is too low, OPcache constantly evicts files and loses most of its benefit.
opcache.max_accelerated_files
opcache.max_accelerated_files limits how many PHP files can be cached. WordPress core alone has a lot of PHP files and plugins add many more. It is recommended to set at least 10,000 to 20,000 for most sites and use higher values for feature-heavy or WooCommerce installs.
opcache.interned_strings_buffer
WordPress reuses strings heavily (class names, hooks, constants). You may want to increase opcache.interned_strings_buffer from the default 8MB to 16-32MB (or 64MB for large sites) to reduce memory duplication and fragmentation.
Timestamp validation
If your site relies on automatic updates, keep ‘opcache.validate_timestamps=1’ with a reasonable revalidate_freq. If you deploy via Git or CI/CD, disabling timestamp checks and flushing OPcache on deploy delivers maximum performance.
These settings apply primarily to self-hosted WordPress environments, where operators control PHP configuration directly. On Pantheon, for example, these values are set and maintained at the infrastructure level and are not customer-configurable.
OPcache, WordPress and the hosting layer that makes it work
PHP OPcache can deliver dramatic speed and stability gains for WordPress, but only when it’s managed correctly over time. The moment you introduce real-world complexity like plugin updates, traffic spikes, multiple environments or team-based deployments, OPcache stops being a simple toggle and becomes an operational concern. In self-hosted environments, misconfigured memory limits, stale caches or poorly timed updates can quietly erase its benefits or even cause outages.
This is where the difference between self-hosted and managed WordPress becomes most visible. Managed platforms treat OPcache as part of a broader WebOps system. On Pantheon, OPcache is part of the PHP runtime (not an application-level cache that customers interact with) and is managed automatically during deployments and environment changes. When you deploy new code on Pantheon, OPcache is automatically cleared so WordPress immediately runs the updated code. You don’t need to flush OPcache manually, install special plugins or trigger cache resets from the admin dashboard.
Additionally, when you use Pantheon, you benefit from:
- Containerized environments: Each site runs in an isolated container with its own PHP worker agent, which prevents cache pollution, noisy neighbors and unpredictable performance under load.
- Dev, Test, Live separation: Pantheon’s WebOps workflow ensures OPcache is validated before code reaches production, reducing the risk of stale bytecode or deployment-related errors.
- Git-based deployments: Code is deployed atomically via Git, not edited in place. This avoids partial updates that can leave OPcache serving inconsistent or outdated code.
- Multi-layer caching coordination: Pantheon manages Varnish cache clearing automatically via dashboard or deployment workflows, offers Redis object caching and enables OPcache by default across all environments.
The result is consistent PHP performance as sites scale, evolve and ship faster – without requiring teams to manage OPcache settings, lifecycle or cache clears themselves.
If you want WordPress performance that stays fast under real production pressure, start with Pantheon today and experience the competitive advantage yourself!