Some performance upgrades take hours of tuning. OPcache is the opposite: it ships with PHP, it is usually already switched on, and it quietly makes every PHP request faster. Yet many site owners and even developers have never looked at it, which means they also don't know when it is misconfigured or why a code change didn't seem to "take."
Here is what PHP OPcache does, how to confirm it is working, and which settings are worth understanding.
How PHP runs your code
PHP is an interpreted language. When a request hits index.php, PHP normally has to:
- Read the file from disk.
- Parse it and check the syntax.
- Compile it into opcodes, the low-level instructions the PHP engine executes.
- Run those opcodes.
A WordPress page can load hundreds of PHP files across core, the theme and plugins. Doing steps 1 to 3 for every file on every request is wasted effort, because the code almost never changes between requests.
What OPcache does
OPcache keeps the compiled opcodes in shared memory. The first request compiles a file and stores the result. Every request after that skips straight to step 4 and runs the stored opcodes.
The result is less CPU work per request and faster responses, especially for large applications like WordPress, Magento, Laravel and Drupal. OPcache has been bundled with PHP since version 5.5, and on most modern hosting it is enabled by default.
OPcache is different from page caching. A page cache stores finished HTML so PHP doesn't run at all. OPcache makes PHP itself faster when it does run. They work well together.
How to check whether OPcache is enabled
There are a few easy ways:
- phpinfo(). Create a temporary file containing
<?php phpinfo();in your site, open it in the browser, and search the page for "Zend OPcache." Look for "Opcode Caching: Up and Running." Delete the file immediately afterward, because phpinfo output reveals details about your server. - Command line. On a VPS, run
php -i | grep opcache.enable. Keep in mind the command-line PHP can use a different configuration from the web server's PHP. - WordPress Site Health. Under Tools > Site Health > Info > Server, you can see the PHP version and extensions. Some hosts and plugins also show OPcache status in their dashboards.
- Control panel. In cPanel or DirectAdmin, the PHP selector or PHP extensions screen often lists
opcacheas a checkbox.
The settings that matter
You will find OPcache settings in php.ini (or a dedicated opcache.ini). On shared hosting you may be able to adjust some through your control panel's PHP options. On a VPS you control them all. The key ones:
opcache.enable
Turns OPcache on for the web server. Should be 1.
opcache.memory_consumption
How much shared memory (in megabytes) OPcache can use to store compiled code. The default in recent PHP versions is 128. A large WordPress site with many plugins, or a server hosting several apps, may need more. If memory fills up, OPcache starts restarting itself or stops caching new files, which hurts performance.
opcache.max_accelerated_files
The maximum number of PHP files that can be cached. WordPress with a dozen plugins can easily include several thousand files. If this number is too low, some files are never cached. Values like 10000 or 20000 are common on servers running large apps.
opcache.interned_strings_buffer
Memory set aside for repeated strings (like class and function names). Raising it from the default can help large codebases.
opcache.validate_timestamps and opcache.revalidate_freq
These control how OPcache notices that a file has changed.
- With
validate_timestamps=1, OPcache checks the file's modification time, at most once everyrevalidate_freqseconds. This is the safe default for most sites, because updates from the WordPress dashboard take effect quickly. - With
validate_timestamps=0, OPcache never checks. That squeezes out a little more speed, but code changes won't show up until you reset OPcache or restart PHP. Use this only if your deployment process handles the reset for you.
Monitoring OPcache
A healthy OPcache has a high hit rate, free memory left over, and no constant restarts. You can check this with:
opcache_get_status()in a small PHP script (keep it private or protected)- Open-source dashboards such as "opcache-gui" for a visual view
- Some WordPress plugins that display OPcache statistics
Signs of trouble include "cache full" flags, frequent OOM restarts, or a number of cached scripts that is pinned at your max_accelerated_files value.
OPcache and deployments
The one time OPcache causes headaches is right after you change code. If you upload new files with SFTP or deploy with Git and the site keeps behaving like the old version, OPcache may still be serving compiled copies.
Ways to handle it:
- Keep
validate_timestamps=1with a shortrevalidate_freq(2 seconds is a common default). - After a deploy, reload PHP-FPM (
sudo systemctl reload php8.3-fpm, adjusting for your version) to clear the cache cleanly. - Call
opcache_reset()from a protected script as part of your deploy.
If you deploy by switching a symlink to a new release folder, be aware OPcache may cache paths using the resolved real path. Reloading PHP-FPM after the switch avoids surprises. Our guide to first steps on a new Linux VPS is a good primer if you are managing PHP yourself.
What about the JIT?
PHP 8 added a JIT (just-in-time compiler) that builds on top of OPcache. It can speed up CPU-heavy code such as image processing or math, but typical web apps like WordPress, which spend much of their time waiting on databases and I/O, usually see little benefit. It is fine to leave the JIT at its default unless you have measured a gain.
Quick checklist
- OPcache shows as enabled for the web server's PHP
- Memory isn't full and the hit rate is high
max_accelerated_filescomfortably exceeds your number of PHP files- You know how changes are picked up after you deploy
- You are on a supported PHP version, since newer versions generally run faster as well
Wrapping up
OPcache is one of the easiest performance wins in the PHP world: it removes repeated compile work so your server spends its effort serving visitors. Confirm it is on, give it enough memory and file slots, and understand how it handles code changes. Do that and you get faster PHP with almost no ongoing effort.