Table of Contents
- Introduction
- TL;DR
- How OPcache Works With WordPress and PHP-FPM
- Check Where You Stand
- The Settings That Matter for WordPress
- opcache.memory_consumption (default 128)
- opcache.interned_strings_buffer (default 8)
- opcache.max_accelerated_files (default 10000)
- opcache.validate_timestamps (default 1) and opcache.revalidate_freq (default 2)
- opcache.save_comments (default 1)
- opcache.enable_cli
- opcache.file_cache (default empty)
- opcache.jit (default “disable” as of PHP 8.4)
- Settings You Can Remove
- GridPane: Changing OPcache per PHP Version
- Shared Servers: Security Settings
- Suggested Starting Configuration
- Tools
- FAQ
- Updates
- Sources
Content Error or Suggest an Edit
Notice a grammatical error or technical inaccuracy? Let us know; we will give you credit!
Introduction
⚡ Short on time? The key facts and fixes are in the TL;DR.
OPcache is PHP’s built-in opcode cache. It compiles each PHP file once and keeps the compiled result in shared memory, so later requests skip parsing and compiling. WordPress loads hundreds of PHP files on every uncached request, and more with WooCommerce or a page builder. That makes OPcache one of the cheapest performance wins you have.
The catch is that PHP’s defaults date from when a site was a few hundred files. A modern WordPress install with 30–60 plugins can fill the default cache on its own. A server running a dozen of them on the same PHP version almost certainly will. When the cache fills, PHP stops caching new files or throws the whole cache away and rebuilds it, and you pay for the compiles again.
This guide covers the settings that matter for WordPress, how to tell whether your cache is full, and how OPcache behaves on PHP-FPM servers like GridPane, RunCloud and cPanel, where every site on a PHP version shares one cache.
TL;DR
- What: OPcache caches compiled PHP in shared memory. WordPress sites routinely outgrow PHP’s defaults (128 MB, 10,000 files, 8 MB interned strings).
- Check first: WordPress 7.0 Site Health now reports whether an opcode cache is enabled. Use
opcache_get_status()through a tool like CacheTool to see whether it’s full. - It’s shared: every PHP-FPM pool under one master shares one OPcache. Size it for all the sites on that PHP version, not per site.
- Starting point:
memory_consumption256–1024,interned_strings_buffer32–64,max_accelerated_filesset above your real PHP file count,validate_timestamps=1. - Don’t: turn off
validate_timestampson WordPress unless your deploys reset OPcache. Plugin, theme and SFTP changes will go stale. - Shared servers: set
opcache.validate_permission=1andopcache.validate_root=1. - GridPane: OPcache is set per PHP version with
gp stack php {version} -opcache-*. GridPane ships a 64 MB cache, so most servers need it raised. See GridPane: Changing OPcache per PHP Version.
How OPcache Works With WordPress and PHP-FPM
On every uncached request, WordPress requires core, your active plugins and your theme. Without OPcache, PHP reads, parses and compiles every one of those files each time. With OPcache, the first request compiles them and stores the opcodes in shared memory, and every later request reuses them.
On PHP-FPM, the cache lives in the FPM master process and is shared by every pool it spawns. The PHP manual says so directly: pools are not a security mechanism, partly because they all use a single OPcache instance.
That has two consequences for WordPress fleets:
- Sizing is per PHP version, not per site. On a typical Debian/Ubuntu stack there’s one
php8.x-fpmmaster per installed PHP version, with a pool per site. Twenty sites on PHP 8.3 share one OPcache. Settingopcache.memory_consumptionin a site’s pool file does nothing, because the segment is allocated once, when the master starts. - Memory is allocated once.
memory_consumption=512costs 512 MB for that master, not 512 MB per worker. That’s often cheaper than people assume.
GridPane uses this layout: one php{version}-fpm service per installed version, with each site’s pool at /etc/php/{version}/fpm/pool.d/{site}.conf, and its OPcache settings apply to the whole PHP version, never per site. To our knowledge RunCloud works the same way. Check where your panel writes PHP-level settings before editing files by hand, since panels often regenerate them.
As of PHP 8.5, OPcache is always compiled in and loaded. You no longer add zend_extension=opcache, and on PHP 8.5 that line now triggers a warning. opcache.enable still controls whether it’s actually used.
Check Where You Stand
WordPress Site Health
WordPress 7.0 added an Opcode cache test to Tools → Site Health and OPcache details under Info → Server. If it reports “Opcode cache is not enabled”, check the server before assuming it’s off. Some hosts restrict opcache_get_status(), and there are open Trac tickets for false negatives on restricted hosts and on file-cache-only setups.
There’s also a proposal to warn when the cache or the interned strings buffer is full. Its reporter says nearly every site he looked at ran OPcache at 100%.
Read the Real Status
php -i from the shell shows the CLI’s settings, not FPM’s. To see what FPM is actually doing, query the FPM socket with CacheTool:
cachetool opcache:status --fcgi=/run/php/php8.3-fpm.sock
What to look for, following Tideways’ breakdown:
- Cache full and
num_cached_keysequalsmax_cached_keys: you’ve run out of slots. Raiseopcache.max_accelerated_files. - Cache full but keys are under the max: you’ve run out of memory. Raise
opcache.memory_consumption. - Interned strings buffer full: raise
opcache.interned_strings_buffer. - Frequent restarts (
oom_restarts,hash_restarts) without a full cache: wasted memory is crossingopcache.max_wasted_percentage. Look at what’s churning before raising it. - Hit rate under ~99% after warm-up: something above is wrong.
The Settings That Matter for WordPress
Defaults below are from the PHP manual. Control panels often ship their own values: GridPane, for example, defaults to 64 MB of OPcache memory and a 60-second revalidate_freq, so check what your servers actually run before tuning.
opcache.memory_consumption (default 128)
The shared memory segment for compiled scripts, in MB. One busy WooCommerce site can use most of the default; a server with many sites will exceed it. Start at 256 for a single site and 512–1024 for a multi-site server, then watch actual usage in the status output and adjust. Remember it’s allocated once per FPM master.
opcache.interned_strings_buffer (default 8)
Memory, in MB, for interned strings: class names, function names, array keys and literals that PHP stores once and reuses. WordPress plugins bring a lot of these, and 8 MB fills quickly. 32 is a sensible single-site start and 64 suits a shared server. As of PHP 8.4 the maximum on 64-bit is 32767 MB.
opcache.max_accelerated_files (default 10000)
The maximum number of scripts the cache can hold. PHP rounds it up to the next prime in a fixed list (for example 20000 becomes 32531) and clamps it to 200–1,000,000.
Set it above the number of PHP files across every site on that PHP version. Count them:
# GridPane-style layout; adjust the path for your panel find /var/www/*/htdocs -name "*.php" | wc -l
Then leave headroom for plugin updates and cache files.
opcache.validate_timestamps (default 1) and opcache.revalidate_freq (default 2)
With validate_timestamps=1, OPcache checks a file’s modification time at most every revalidate_freq seconds and recompiles it if it changed.
Keep validate_timestamps=1 on WordPress. Since WordPress 5.5, core calls wp_opcache_invalidate() on files it replaces during core, plugin and theme updates. That doesn’t cover files changed by SFTP, Git pulls, rsync, a panel’s file manager, or plugins that write their own PHP config files. With timestamps off, those changes stay invisible until you reset the cache or restart FPM.
revalidate_freq is the trade-off between stat calls and how long a change takes to appear. PHP’s default of 2 is fine for most fleets; GridPane ships 60. Raising it to 10–60 saves a little I/O but means SFTP edits can take that long to show up. WordPress core contributors have pushed back on recommending high values because of the risk of stale or mixed code.
opcache.save_comments (default 1)
Leave it on. Turning it off drops docblocks from the cache, which breaks code that reads annotations or attributes from comments. Some plugins and bundled libraries do.
opcache.enable_cli
Controls OPcache for the PHP CLI, which includes WP-CLI and cron run through wp cron. Each CLI run is a fresh process with its own empty cache, so enabling it mostly adds startup overhead unless you also use opcache.file_cache. Leave it off unless you’ve measured a benefit. GridPane’s docs describe it as mainly for debugging OPcache itself and not suitable for most users.
opcache.file_cache (default empty)
A second-level cache on disk. When the shared memory cache is reset or FPM restarts, PHP can reload compiled scripts from disk instead of recompiling everything. It’s useful on large fleets after a PHP-FPM restart. The directory must be writable by the PHP user.
opcache.jit (default “disable” as of PHP 8.4)
The PHP 8 JIT compiles hot code paths to machine code. It mainly helps CPU-bound work. Typical WordPress requests spend most of their time in the database and I/O, so leave it disabled unless you’ve benchmarked a gain on your own sites. Before PHP 8.4 the default mode was tracing, but with jit_buffer_size=0 it wasn’t actually active. In 8.4 it’s off by setting the mode to disable, and the buffer defaults to 64M.
Settings You Can Remove
opcache.fast_shutdown was removed in PHP 7.2; PHP now uses a variant of it automatically. If it’s in an old config, delete it.
GridPane: Changing OPcache per PHP Version
GridPane exposes OPcache through gp stack php. Every setting applies to one PHP version and every site using it, never to a single site. GridPane writes the values to /etc/php/{version}/fpm/php.ini, so use the gp commands rather than editing that file by hand.
| Directive | GridPane command | GridPane default |
|---|---|---|
opcache.enable | gp stack php {version} -opcache-enable / -opcache-disable | Enabled |
opcache.enable_cli | gp stack php {version} -opcache-enable-cli / -opcache-disable-cli | Disabled |
opcache.memory_consumption | gp stack php {version} -opcache-memory {MB} | 64 |
opcache.max_accelerated_files | gp stack php {version} -opcache-max-accel-files {count} | 10000 |
opcache.revalidate_freq | gp stack php {version} -opcache-reval-freq {seconds} | 60 |
Check What Each Version Runs Now
# OPcache values for every installed PHP version (FPM, not CLI) grep -H '^opcache\.' /etc/php/*/fpm/php.ini # Which PHP version each site uses, so you know which versions to size ls /etc/php/*/fpm/pool.d/
Then count the PHP files on the sites for each version (see max_accelerated_files above) to pick a key count.
Change One PHP Version
Each gp stack php command reloads that PHP version on its own. When you change several settings, add -no-reload to each one and reload once at the end:
gp stack php 8.3 -opcache-memory 512 -no-reload && gp stack php 8.3 -opcache-max-accel-files 100000 -no-reload && gp stack php 8.3 -opcache-reval-freq 2 -no-reload && gp php 8.3 reload
Change Every Installed PHP Version
for ver in $(ls /etc/php | sort -V); do [ -f "/etc/php/$ver/fpm/php.ini" ] || continue echo "== PHP $ver" gp stack php "$ver" -opcache-memory 512 -no-reload && gp stack php "$ver" -opcache-max-accel-files 100000 -no-reload && gp stack php "$ver" -opcache-reval-freq 2 -no-reload && gp php "$ver" reload done
Size each version for the sites that actually run on it. A version with two small sites doesn’t need the same cache as one hosting your WooCommerce stores, and each version’s cache is a separate allocation of RAM.
Verify
grep -H '^opcache\.' /etc/php/*/fpm/php.ini
Then confirm what FPM is really using, with CacheTool against any site’s pool socket on that version (they all share the version’s cache), using opcache:configuration for the settings and opcache:status for usage. If the new memory size doesn’t show, restart that PHP version (gp php 8.3 restart) instead of reloading.
Settings GridPane Doesn’t Expose
GridPane’s docs don’t list a gp command for opcache.interned_strings_buffer, validate_timestamps, validate_permission or validate_root. If you need them, ask GridPane support where a persistent override belongs before adding your own ini file. A hand edit to php.ini may be overwritten the next time GridPane rewrites it.
Because every pool under one master shares the cache, set these in the master’s ini on any server hosting more than one site or customer:
opcache.validate_permission=1: checks that the requesting user can read the file before serving it from the cache.opcache.validate_root=1: prevents cache key collisions between chrooted sites with identical paths.opcache.restrict_api: limits which scripts can callopcache_reset()and friends. If you set it, make sure it still includes each site’s WordPress root.wp_opcache_invalidate()checksrestrict_apiand silently skips invalidation when WordPress isn’t allowed to call it.
For strict separation between customers, the PHP project’s advice is separate FPM masters, not separate pools.
Suggested Starting Configuration
Put this in the FPM master’s config for each PHP version (for example /etc/php/VERSION/fpm/conf.d/99-opcache.ini). Use your panel’s PHP settings if it manages them. Then restart that PHP-FPM service, because these values are only read at master start. On GridPane, use the gp stack php commands in the GridPane section instead of an ini file.
Single site or small VPS
opcache.enable=1 opcache.memory_consumption=256 opcache.interned_strings_buffer=32 opcache.max_accelerated_files=20000 opcache.validate_timestamps=1 opcache.revalidate_freq=2 opcache.save_comments=1
Many sites on one PHP version
opcache.enable=1 opcache.memory_consumption=1024 opcache.interned_strings_buffer=64 opcache.max_accelerated_files=100000 opcache.validate_timestamps=1 opcache.revalidate_freq=2 opcache.save_comments=1 opcache.validate_permission=1 opcache.validate_root=1
These are starting points, not answers. Check status after a day of normal traffic and adjust using the checklist above.
Tools
WordPress plugins (inside the dashboard)
- WP OPcache (Flush OPcache): adds an admin-bar flush button, shows memory, hit and JIT statistics, and includes a WP-CLI command. It flushes only files within that WordPress install, which matters on shared servers.
- OPcache Manager: statistics and history for OPcache from the dashboard.
On a shared FPM master, any site’s plugin sees the whole server’s cache stats, not just its own.
Standalone
- CacheTool: CLI. Queries the FPM socket directly, so it’s the most reliable view of what FPM is doing.
- OPcache GUI by amnuts: a single-file web dashboard. Don’t leave it publicly reachable.
FAQ
Do I need OPcache if I use full-page caching?
Yes. Page caching (FastCGI cache, Cloudflare APO, WP Rocket) skips PHP for cached hits. OPcache speeds up everything that still reaches PHP: logged-in users, wp-admin, WooCommerce cart and checkout, REST and AJAX calls, and cache misses.
Is OPcache the same as an object cache like Redis?
No. OPcache caches compiled PHP code. An object cache (Redis, Memcached) caches data, mainly database query results. You want both.
Why does my plugin show cache stats for sites that aren’t mine?
Because all pools under one FPM master share one cache. See Shared Servers above.
Do I need to flush OPcache after updating WordPress?
Not for updates run through WordPress itself: since 5.5 core invalidates the files it replaces. You do need to if you’ve disabled validate_timestamps, or if files changed outside WordPress and you can’t wait revalidate_freq seconds.
Updates
- 11/24/2026: Rewritten for current PHP (8.4 JIT defaults, 8.5 always-loaded OPcache) and WordPress (7.0 Site Health opcode cache test). Added PHP-FPM shared-cache sizing, invalidation, security settings and starting configurations. Added a GridPane section with
gpcommands for each PHP version. Removedopcache.fast_shutdown(dropped in PHP 7.2). - 12/14/2022: Article created.
Sources
- PHP Manual: OPcache runtime configuration
- PHP Manual: FPM configuration (pools share a single OPcache)
- PHP RFC: Make OPcache a non-optional part of PHP (PHP 8.5)
- Make WordPress Core: Opcode Cache Invalidation in WordPress 5.5
- WordPress Trac #51686: Invalidate OPcache for version.php during core update
- WordPress Developer Reference: WP_Site_Health::get_test_opcode_cache() (7.0)
- WordPress Trac #63697: Add OPcache to Site Health
- WordPress Trac #64854: Site Health warning for a full OPcache
- WordPress Trac #65395: Opcode cache false negatives on restricted hosts
- Tideways: Fine-Tune Your Opcache Configuration to Avoid Caching Surprises
- Mattias Geniar: Mitigating PHP’s long-standing issue with OPcache leaking sensitive data
- cPanel: PHP 8.5 OPcache
- GridPane KB: Configure PHP
- CacheTool
- linuxblog.io: PHP performance: OPcache Control Panels
