Speed & performance · Explainer
What Is PHP OPcache and Does WordPress Need It?
Short answer
PHP OPcache is a built-in extension that stores precompiled PHP bytecode in shared memory, so PHP does not recompile the same files on every request. WordPress does not require it, but most hosts turn it on because WordPress runs hundreds of PHP files per page load.
Key takeaways
- OPcache stores compiled PHP bytecode in shared memory and has been bundled with PHP since version 5.5.0.
- It caches code, not HTML pages, so it is a different layer from a page cache or an object cache.
- The default shared memory size is 128 MB and the default file limit is 10000 scripts.
- With validate_timestamps off, code changes only take effect after a manual reset or a PHP restart.
- The JIT compiler inside OPcache is off by default and most WordPress sites should leave it off.
What is PHP OPcache?
PHP OPcache is a built-in extension that stores precompiled PHP bytecode in shared memory so PHP does not have to read and compile the same files on every request.
Every WordPress page runs PHP code. Without OPcache, PHP reads each file, parses it, and compiles it into bytecode on each request. With OPcache, that work happens once, and later requests reuse the stored bytecode.
The PHP manual states that OPcache improves PHP speed by storing precompiled script bytecode in shared memory. It also states that the extension is bundled with PHP 5.5.0 and later.
OPcache is not a page cache. It does not store HTML output, images, or database results. It stores compiled code only, and a site can use both layers at once.
How does OPcache work?
OPcache sits between PHP and your files, and it serves compiled code from memory when a file has already been compiled.
The first time PHP runs a file, it reads the source, parses it, and compiles it into opcode, which is the instruction set the Zend Engine runs. OPcache saves that opcode in a shared memory segment.
On the next request for the same file, PHP checks the cache first. If the file is there and unchanged, PHP runs the stored opcode straight away. That skips the read, parse, and compile steps for that file.
All PHP workers in the same pool share one OPcache memory segment, so a single page load that runs dozens of core, theme, and plugin files compiles each file once and reuses it.
OPcache also stores interned strings, which are repeated text values such as function names, in a shared buffer. The PHP manual lists that buffer at 8 MB by default, and the shared memory size at 128 MB (PHP manual: OPcache configuration).
Does WordPress need OPcache?
WordPress does not require OPcache, but almost every WordPress site runs better with it on.
WordPress is written in PHP, so every page, post, and admin screen runs PHP files. A plain page load can involve hundreds of files from core, the active theme, and plugins.
OPcache removes the repeated compile cost for all of them, which is why WP Rocket describes it as a cache that saves precompiled bytecode in server memory for faster repeat loads (WP Rocket: what is OPcache).
Most managed WordPress hosts turn OPcache on by default. On shared hosting, it is usually on too, because the host sets it in the server PHP settings. If your host leaves it off, PHP still works, but it compiles the same files again on each request.
WordPress.org recommends PHP 8.3 or greater for hosts, and it notes that WordPress still runs on PHP 7.4 and newer (WordPress.org requirements). OPcache ships with every one of those PHP versions, since it has been bundled since PHP 5.5.0.
The Make WordPress Hosting handbook notes that PHP 8.4 or later is recommended for production use, and that PHP 8.3 moved to security-only support on 31 December 2025 (Make WordPress Hosting server environment). Each PHP version has its own OPcache, so a version switch starts with an empty cache that fills as pages are requested.
You do not need a plugin to use OPcache. It runs at the PHP level, below WordPress, and no WordPress setting turns it on or off. Your host or server admin controls it through php.ini.
How do you check if OPcache is on?
You can check OPcache from the WordPress dashboard in under a minute, and a small PHP file gives a fuller answer.
Open Tools > Site Health in wp-admin, then open the Info tab and expand the Server section to confirm your PHP version. That screen does not show OPcache directly, so use a small PHP file for the direct check.
For a direct OPcache check, create a file named opcache-check.php in your site root with this code, open it in a browser, then delete it right away:
<?php
var_dump(extension_loaded('Zend OPcache'));
var_dump(opcache_get_status(false));
The first line tells you if the extension is loaded. The second line returns status data, including memory use, hit counts, and the number of cached scripts. Delete the file when done, because it exposes server details.
If you have SSH access, run php -i | grep -i opcache to see the OPcache settings for the command-line PHP build. The PHP manual lists opcache.enable_cli with a default of 0, so the CLI build usually has OPcache off while the web build has it on.
If the check shows OPcache off, ask your host to turn it on, since shared hosting often blocks direct php.ini edits.
What do the main OPcache settings mean?
OPcache has dozens of settings, but six of them cover most WordPress sites.
| Setting | Default | What it controls |
|---|---|---|
opcache.enable | 1 | Turns the opcode cache on or off |
opcache.memory_consumption | 128 MB | Size of the shared memory segment |
opcache.interned_strings_buffer | 8 MB | Memory for shared text values |
opcache.max_accelerated_files | 10000 | Most scripts the cache can hold |
opcache.validate_timestamps | 1 | Checks files for changes |
opcache.revalidate_freq | 2 seconds | How often it checks for changes |
All six defaults come from the PHP manual OPcache configuration page, checked November 2026.
opcache.memory_consumption sets the shared memory size in MB. The manual states the smallest allowed value is 8 MB. A 128 MB default is fine for a small site, but a site with many plugins may fill it, and a full cache restarts and drops cached files.
opcache.max_accelerated_files sets the most script keys the cache hash table can hold. The manual states the smallest allowed value is 200 and the largest is 1000000. The default of 10000 covers most WordPress sites, but a site with a large plugin set may pass it.
opcache.validate_timestamps decides whether OPcache checks file timestamps. With the default of 1, it checks each file at most every opcache.revalidate_freq seconds, which defaults to 2. With a value of 0, it never checks, and code changes only take effect after a manual reset or a PHP restart.
How do you turn OPcache on or off?
You turn OPcache on in php.ini, not in WordPress, and on shared hosting you usually need your host to do it.
If you control the server, open the php.ini file your web PHP build uses and add or change these lines:
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
Then restart PHP-FPM or Apache so the new settings load. A php.ini change does nothing until the PHP process restarts.
On shared hosting, look for a PHP settings screen in your host panel first. If there is no OPcache switch, open a support ticket and ask for it to be turned on.
To turn OPcache off for a short test, set opcache.enable=0 in php.ini and restart PHP, then turn it back on. The PHP manual notes that opcache.enable cannot be turned on at run time with ini_set().
When does OPcache serve stale code?
OPcache can serve old code after a file changes, and the cause is almost always the timestamp check settings.
With the defaults, OPcache checks a file timestamp at most once every 2 seconds, because opcache.revalidate_freq defaults to 2. If you edit a file twice in the same 2-second window, the second edit may wait for the next check.
The real stale-code trap is opcache.validate_timestamps=0. Some hosts set it to 0 for speed. The PHP manual states that when this setting is off, you must reset OPcache by hand with opcache_reset(), opcache_invalidate(), or a web server restart before file changes take effect.
Deployments are the common trigger. If you upload new plugin files while PHP workers are running, some requests may still run the old cached files, so restart PHP-FPM after a deploy or call opcache_reset() as part of it.
If a change does not appear after an upload, check OPcache before you blame the page cache. A page cache stores HTML, while OPcache stores code, and clearing one does not clear the other. See our guide on page cache vs object cache for how the layers differ.
What is the difference between OPcache and a page cache?
OPcache caches compiled PHP code, while a page cache stores finished HTML pages, and they solve different problems.
A page cache saves the full HTML output of a page. When a visitor asks for a cached page, the server sends that HTML without running PHP or asking the database. That is why a page cache can make a page load fast even on a slow server.
OPcache does not skip PHP. It only skips the compile step. PHP still runs on each request, and WordPress still asks the database for posts, options, and user data.
An object cache is a third layer. It stores database query results and computed values in memory, often in Redis or Memcached. Our guide on how to set up Redis object cache covers that layer in detail.
A typical WordPress stack uses all three at once. OPcache handles code, the object cache handles data, and the page cache handles finished HTML, so turning one off does not turn the others off. Server-level caching adds a fourth layer on some hosts, as our explainer on server-level caching describes.
What is the OPcache JIT, and should you turn it on?
The JIT is a just-in-time compiler inside OPcache, and most WordPress sites should leave it off.
The JIT arrived in PHP 8.0 as part of OPcache. It takes hot opcode, which is code that runs often, and compiles it further into native machine code. That can help code with long loops and heavy math.
The PHP manual lists opcache.jit with a default of “disable”, and it notes that before PHP 8.4.0 the default was “tracing”. It also lists opcache.jit_buffer_size with a default of 64M since PHP 8.4.0, when the prior default was 0.
WordPress is not the workload the JIT helps most. WordPress spends its time on database queries, file reads, and short request handling, not on long-running math. The JIT adds memory use and warm-up time for little gain on a normal site.
Leave opcache.jit at its default unless you run a specific workload that benefits from it, such as heavy image math or long data processing in PHP.
If you do turn it on, set a buffer size and watch memory use. The JIT buffer lives inside the OPcache shared memory segment, so it adds to the total the manual describes.
Do not confuse the JIT with OPcache itself. OPcache is on by default in most PHP builds, while the JIT is off by default.
What mistakes should you avoid?
The most common OPcache mistakes are small settings errors that are easy to prevent.
First, do not set opcache.validate_timestamps=0 on a site you edit often. It is a valid speed choice for a frozen production deploy, but code edits will not show until you reset the cache or restart PHP.
Second, do not set opcache.memory_consumption too low. The default is 128 MB, and the manual enforces a floor of 8 MB. A site with many plugins can fill 128 MB, and a full cache restarts and drops files.
Third, do not set opcache.max_accelerated_files below your file count. The default is 10000, and the manual caps the value at 1000000. If your site has more PHP files than the limit, some files will never stay cached.
Fourth, do not assume OPcache fixes slow database queries or slow external calls. It only removes the compile step, so if your site is slow because of queries, use an object cache and check slow queries first.
Our guide on whether the PHP version affects speed puts the PHP layer in context with the other speed factors.
Frequently asked questions
Is OPcache on by default in PHP?
OPcache is on by default once the extension is loaded, because opcache.enable defaults to 1. Whether it is loaded depends on your PHP build and your host. Check with a small PHP file that calls opcache_get_status, or ask your host.
Does OPcache replace a caching plugin?
No. OPcache caches compiled PHP code, while a caching plugin stores finished HTML pages. They work at different layers and a site can use both. Clearing one does not clear the other, so check both when a change does not appear.
How do I clear OPcache after changing code?
Restart PHP-FPM or Apache, or call opcache_reset from a PHP script. With the default settings, OPcache checks file timestamps every 2 seconds, so small edits usually appear fast. If validate_timestamps is off, a manual reset is required.
Can OPcache break my WordPress site?
OPcache itself rarely breaks a site. Stale code is the usual problem, and it happens when validate_timestamps is off and no reset follows a deploy. Turn the setting back on or restart PHP after uploads to fix it.
How much memory should OPcache use?
The default is 128 MB, which suits a small site. A site with many plugins may fill it, and a full cache restarts and drops files. Check opcache_get_status for memory use and restarts, then raise memory_consumption in php.ini if needed.
Sources
- OPcache PHP Manual
- OPcache Runtime Configuration PHP Manual
- Requirements WordPress.org
- Server Environment Make WordPress Hosting
- OPcache: What It Is and How to Enable It on WordPress WP Rocket
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
