OPcache for WordPress: What It Does, Why It Matters, and How to Confirm It's Working
PHP OPcache is one of the most impactful WordPress performance features that most site owners never think about. It stores compiled PHP bytecode in memory so WordPress doesn’t need to recompile PHP files on every request. The performance difference between OPcache enabled and disabled can be 2-3x for WordPress page generation. Yet many hosting environments run with suboptimal OPcache settings or have it disabled entirely.
What OPcache does
Every WordPress page load requires executing PHP code. PHP is an interpreted language—each request reads PHP files, parses them, compiles them to bytecode, then executes the bytecode. Without OPcache, this compilation happens on every single request, even though the PHP files haven’t changed.
OPcache stores the compiled bytecode in shared memory. The first request compiles normally and stores the result. Subsequent requests skip the entire compile step and jump straight to execution. For WordPress, which loads dozens of PHP files per request (core, theme, plugins), skipping compilation saves significant time.
The impact scales with code size. A minimal WordPress installation compiles faster than a site with 30 plugins and a complex theme. But the more code you have, the more OPcache saves—because there’s more compilation to skip. Heavy WordPress installations benefit the most from OPcache.
Why it matters for WordPress specifically
WordPress loads many PHP files per request. Core WordPress alone includes hundreds of PHP files. Add a theme and plugins, and a typical request touches 200-400 PHP files. Each file requires parsing and compilation without OPcache.
The compilation overhead compounds with plugins. Each plugin adds its own PHP files to the execution path. A site with 30 active plugins might execute 50+ additional PHP files per request. OPcache ensures these files compile once and serve from memory for all subsequent requests.
PHP worker efficiency depends on OPcache. Each PHP worker processes requests sequentially. If compilation takes 100ms and execution takes 200ms, each request takes 300ms. With OPcache eliminating compilation, the same request takes 200ms—a 33% improvement in worker throughput. This effectively increases your site’s capacity without adding workers.
How to confirm OPcache is enabled
Create a PHP info file to check OPcache status. Add a file to your WordPress root containing <?php phpinfo(); ?> and access it through your browser. Search for “OPcache” in the output. You should see “Zend OPcache” listed with status “Enabled” and “Caching” shown as “Up and Running.”
Alternatively, access your hosting control panel. Many managed WordPress hosts expose PHP settings through their dashboard. Look for OPcache or PHP caching settings. Quality hosts enable OPcache by default with reasonable settings.
If you have SSH access, run php -i | grep opcache to check OPcache configuration from the command line. This shows all OPcache settings and their current values.
Important: remove any phpinfo file after checking. It exposes server configuration details that could be useful to attackers.
Key OPcache settings for WordPress
opcache.memory_consumption controls how much memory OPcache uses. WordPress sites with many plugins need 128-256MB. The default 128MB works for moderate installations. If your cache fills and starts evicting, increase this value.
opcache.max_accelerated_files limits how many files OPcache can store. WordPress sites easily exceed the default 10,000 files. Set this to at least 20,000 for sites with multiple plugins. Under-setting this causes frequent cache churn and defeats OPcache’s purpose.
opcache.validate_timestamps controls whether OPcache checks if files have changed. When enabled (default), OPcache checks file modification times periodically. When disabled, OPcache never rechecks—maximum performance but changes to PHP files require manually clearing OPcache.
opcache.revalidate_freq sets how often (in seconds) OPcache checks for file changes when validation is enabled. The default 2 seconds works for development. Production sites can increase to 60-120 seconds, reducing filesystem checks while still eventually detecting changes.
Common OPcache problems
OPcache too small for the installation. If memory fills completely, OPcache starts evicting cached bytecode. Frequent eviction means files are repeatedly recompiled, negating OPcache’s benefit. Monitor OPcache usage through a status page or hosting dashboard.
OPcache not clearing after updates. When you update WordPress, themes, or plugins, old cached bytecode may persist if timestamps aren’t validated or revalidation is infrequent. Some hosting platforms automatically clear OPcache on file changes. Others require manual restart or cache clearing.
Multiple PHP versions with separate OPcache pools. Some hosting runs multiple PHP versions with independent OPcache instances. Ensure OPcache settings are configured for your active PHP version, not just the default.
Shared hosting OPcache contention. On shared hosting, OPcache memory may be shared among accounts. High memory pressure from other accounts can evict your cached bytecode. This creates inconsistent performance that’s difficult to diagnose without monitoring OPcache hit rates.
Monitoring OPcache health
OPcache hit rate should be 95%+ for a properly configured installation. A rate below 80% indicates either insufficient memory, too many files for the configured limit, or frequent cache invalidation.
Track OPcache restarts. Frequent restarts indicate memory pressure or configuration issues. Each restart clears the entire cache, temporarily degrading performance until the cache warms again.
Compare TTFB with and without OPcache using A/B testing or before/after measurement. The difference quantifies OPcache’s contribution to your specific installation. For most WordPress sites, expect 30-50% faster PHP execution with OPcache properly configured.
The practical takeaway
OPcache is the simplest high-impact WordPress performance optimisation. It requires no code changes, no plugin installation (it’s a PHP module), and minimal configuration. If it’s not enabled on your hosting, that’s the single highest-priority fix you can make.
For sites already running OPcache, verify the configuration matches your installation’s needs: adequate memory, sufficient file limits, and appropriate validation settings. A well-tuned OPcache configuration silently improves every page load.
OPcache works alongside other caching layers—it speeds up PHP execution, object caching reduces database load, and page caching skips PHP entirely for cached pages. Together, these layers create a comprehensive performance stack that handles traffic efficiently. If you’re unsure whether your hosting’s PHP configuration is optimal, our performance service includes server-side profiling that reveals exactly where execution time is spent.