Every time WordPress handles a request, PHP needs to read hundreds of PHP files, from core, the theme and every active plugin, and compile them into bytecode before running them. Without caching, that compilation happens again on every single request. OPcache solves this by storing the compiled bytecode in shared memory, so subsequent requests skip the compilation step entirely. Tuning OPcache for WordPress properly is how you get that benefit back.
OPcache has been bundled with PHP since version 5.5 and is enabled on almost every hosting setup. That’s the good news. The less good news is that its default settings were chosen to be safe for small applications, not for a WordPress site with a heavy theme, WooCommerce and forty plugins. When OPcache runs out of memory or file slots, it quietly stops caching some files, and you lose much of the benefit without any error message. Tuning OPcache for WordPress takes a few minutes and is one of the cheapest server-side performance improvements available.
How OPcache works in brief
When PHP first loads a file, OPcache compiles it and stores the result in a shared memory segment. On later requests, PHP checks whether the cached version is still valid and, if so, uses it directly. Because the memory is shared between all PHP-FPM worker processes in a pool, one worker’s compilation benefits all the others.
Three limits matter most:
- Memory: how much space is available for compiled code
- Number of files: how many separate scripts can be cached
- Interned strings buffer: a separate area for strings that appear repeatedly in code
If any of these fills up, OPcache can no longer cache new files. Depending on settings, it may restart and clear the entire cache, which causes a burst of slow requests while everything recompiles.
Checking your current status
Before changing anything, look at what’s happening now. The simplest method is a small PHP script, placed somewhere private and deleted afterwards:
Run it through the web server, not the command line, because the CLI has its own separate OPcache. Alternatively, use a dashboard tool such as opcache-gui, protected behind authentication.
What to look for:
- A hit rate above 99 percent on a warmed-up site is normal. Lower numbers suggest the cache is too small or being reset frequently.
- Memory usage close to the limit means you need more.
- Cached scripts close to the maximum means you need more file slots.
- Any out-of-memory restarts mean the cache filled up and was wiped.
The key settings
OPcache settings live in php.ini or a separate file such as /etc/php/8.3/fpm/conf.d/10-opcache.ini. Change them for PHP-FPM, then restart the PHP-FPM service.
opcache.memory_consumption
The default is 128 MB. A simple WordPress site uses far less, but a site with WooCommerce, a page builder and many plugins can use 100 MB or more. If you host several sites in the same PHP-FPM pool, they share the cache.
A reasonable starting point:
Then check usage after the site has been running for a while. Aim to keep used memory under about 75 percent of the limit, leaving room for updates that add new files.
opcache.max_accelerated_files
This sets how many PHP files can be cached. The default is 10,000. WordPress core alone has well over a thousand PHP files, and WooCommerce adds thousands more. A busy site with many plugins can easily exceed the default.
PHP rounds the value up to the next prime number from a fixed set, so the actual number may be slightly different. Count your PHP files to get a sense of what you need:
| <code>find /var/www -type f -name "*.php" | wc -l</code> |
|---|
Set the limit comfortably above that number, especially if several sites share the pool.
opcache.interned_strings_buffer
The default of 8 MB is often too small for large WordPress installations. When it fills, OPcache stops interning new strings, which reduces efficiency. Increasing it costs little:
opcache.validate_timestamps and opcache.revalidate_freq
By default, OPcache checks whether a file has changed on disk, at most every two seconds, controlled by revalidate_freq. That’s what lets plugin updates through the dashboard take effect immediately.
You can reduce the overhead by checking less often:
With a 60-second interval, a changed file may take up to a minute to take effect. For most production sites, that’s an acceptable trade-off.
Some high-performance setups disable timestamp validation entirely with validate_timestamps=0. Then OPcache never checks the disk, and code changes only take effect after PHP-FPM is reloaded or the cache is reset. That’s the fastest option, but it’s risky on WordPress sites where plugins update through the dashboard. Updated files on disk wouldn’t match cached code, and a half-applied update can cause errors that are hard to diagnose. Only use it if every code change goes through a deployment process that reloads PHP-FPM.
opcache.save_comments
Leave this at the default of 1. Some plugins and libraries read PHP docblock comments at runtime, for example for annotations. Disabling comment saving can break them.
A sensible configuration for most WordPress servers
Adjust memory and file counts based on what you see in the status output. Restart PHP-FPM after changes:
What about the JIT?
PHP 8 introduced a just-in-time compiler that can turn bytecode into machine code. It was widely publicised, and people often ask whether to enable it for WordPress.
For typical WordPress workloads, the JIT makes little difference. WordPress spends most of its time waiting on the database, doing string manipulation and calling functions, not running tight numerical loops where JIT excels. Benchmarks generally show small gains at best, and occasionally it has exposed bugs. It also uses additional memory.
You can experiment with it on staging:
Measure real response times before and after. If you see no meaningful improvement, leave it off. In my experience, memory and file count tuning matter far more.
Preloading
PHP 7.4 added preloading, where a script loads specified files into OPcache when PHP-FPM starts, keeping them permanently in memory. It can help frameworks with a stable set of files. For WordPress, where the set of loaded files depends on active plugins and changes with every update, preloading adds complexity for little gain. Most WordPress hosts don’t use it, and I don’t recommend it for typical sites.
Avoiding stale code after deployments
If you deploy code with Git, rsync or a deployment tool, a common issue is OPcache serving old versions of files for a short time. With validate_timestamps enabled and a long revalidate_freq, changes can take up to that many seconds to appear. With symlink-based deployments, where a symlink switches to a new release folder, OPcache may continue using the old paths until reset.
The reliable fix is to reload PHP-FPM, or reset OPcache, as the final step of every deployment. A graceful reload doesn’t drop requests:
Shared hosting and managed hosts
On shared and managed hosting, you usually can’t change OPcache settings yourself. Some hosts expose a few options in their control panel or allow overrides in a .user.ini file, but memory size and file limits are typically fixed at the server level. If your status output shows the cache is full, ask your host. A host that tunes OPcache for WordPress properly is a good sign.
Measuring the result
After tuning, compare uncached response times, for example for logged-in admin pages or a WooCommerce cart, before and after. Look at:
- Time to first byte on uncached pages
- PHP-FPM CPU usage under normal traffic
- The OPcache hit rate and out-of-memory restart count after a few days
On sites where the cache was undersized, I’ve seen admin and checkout pages become noticeably snappier after nothing more than raising the memory and file limits. Tuning OPcache for WordPress isn’t glamorous, but it’s a one-off change that keeps paying back on every single request.
OPcache and multiple sites
When several WordPress sites share a server, think about how OPcache memory is divided. By default, all PHP-FPM pools running under the same PHP version share one OPcache memory segment. A server with ten sites, each with WooCommerce and twenty plugins, can easily need more than the default allocation, because every site’s files are cached separately even when they’re identical copies of the same plugin.
Check the status output with all sites warmed up, not just one, and size memory and file limits for the combined load. If you’ve separated sites into different pools for security, also be aware that OPcache’s shared memory can, in some configurations, let one pool see cached data from another. The opcache.validate_root and opcache.validate_permission settings add checks that reduce this risk on multi-user servers, and they’re worth enabling when untrusted sites share a host.
A quick troubleshooting checklist
If changes to PHP files don’t seem to take effect, the cause is usually OPcache: check revalidate_freq and reload PHP-FPM. If the hit rate stays low, look for an undersized cache or frequent restarts. If memory keeps filling after updates, old versions of files may be lingering, and a scheduled reload during quiet hours clears them. And if a site suddenly becomes slower after adding a big plugin, check whether max_accelerated_files has been reached.
Frequently asked questions
Is OPcache the same as page caching?
No. OPcache caches compiled PHP code. Page caching stores whole HTML pages so PHP doesn’t run at all. They work together.
Does OPcache help logged-in users and WooCommerce checkout?
Yes. Those requests bypass page caching, so they rely entirely on PHP performance, which is exactly where OPcache helps most.
How much memory should I give OPcache?
Enough to keep usage below about 75 percent with room for growth. For a single large WordPress site, 192 to 256 MB is usually plenty.
Will changing OPcache settings cause downtime?
A PHP-FPM restart briefly interrupts processing. A reload is gentler. Schedule changes for quiet times either way.




