OPcache is one of those things that usually comes up sideways. A host’s support reply says “OPcache is enabled on your account”. A server report lists it under PHP extensions. A developer asks you to check it before they look at anything else. You nod, and quietly wonder what it is and whether you should do anything about it.
The short version: in most cases your host has already handled it. The longer version, with PHP OPcache explained step by step, is still worth ten minutes, because it tells you what to ask when uncached pages are slow, and why a file you just edited can keep behaving like the old one.
What PHP has to do before it can run your site
WordPress, your theme and your plugins are written in PHP. Those files are plain text, readable by a person. A computer cannot run them as they are. Every time a PHP file is needed, PHP has to:
- Read the file from disk.
- Check the text for structure, the way a reader breaks a sentence into words and grammar.
- Compile it into a list of low-level instructions called opcodes.
- Run those opcodes.
A single uncached WordPress page load can involve hundreds of files. Without an opcode cache, steps 1 to 3 are repeated for every one of them, on every request, even though the files have not changed since yesterday.
PHP OPcache explained: what it keeps, and where
OPcache stores the compiled opcodes from step 3 in the server’s shared memory. The next time a file is needed, PHP skips straight to step 4 and runs the instructions it already has. Reading from memory is much faster than reading and compiling text, so every request that runs PHP gets cheaper.
A few things follow from where it lives:
- It is a server-side cache. Visitors never see it, and there is nothing to clear in their browsers.
- It is shared between all the requests the server’s PHP handles, so the first request after a restart fills it and the rest benefit.
- It is emptied when PHP restarts, when the host reloads the server, and when it is reset deliberately.
- It has a fixed amount of memory. If your code does not fit, some of it is compiled again and again.
In our overview of the five caches behind a fast website, OPcache is the layer furthest from the visitor and the one people least often think about.
What an opcode cache does not do
It helps to be clear about the limits, because OPcache is sometimes mentioned as if it were a fix for everything.
- It is not a page cache. WordPress still runs all of its code and queries the database for every uncached page. OPcache only removes the compile step.
- It does not store database results. That is the job of an object cache. The two work at different layers, and our post on when Redis object caching helps covers the second one.
- It does not make slow code fast. A plugin that runs a heavy query or calls an outside service on every page is just as slow with OPcache. The compile time was never its problem.
- It does nothing for images, CSS or JavaScript. Those are sent as files and are cached by the browser and CDN instead.
Think of it as removing a fixed overhead from every PHP request. It matters most where there are many uncached requests: logged-in users, shops, the admin area, AJAX calls and busy sites with low page cache hit rates.
Is OPcache switched on for your site?
OPcache has been bundled with PHP for many years, and almost every reputable host enables it. Still, it is worth confirming, especially on a cheap plan, a self-managed VPS or a server that someone set up by hand.
Check the hosting panel
Many control panels have a PHP settings or PHP extensions page for each site. Look for opcache in the list of extensions and whether it is ticked. Some panels let you switch it on yourself.
Use a temporary phpinfo page
Create a file in the site’s root folder containing a single phpinfo() call, open it in your browser and search the page for “opcache”. You will see whether it is enabled and its current settings. Delete the file straight afterwards. It exposes a lot of detail about your server that should not be public.
Ask the host
A short question, “Is OPcache enabled for PHP on my account, and how much memory does it have?”, gets a clear answer from most hosts and avoids guesswork. One caution: PHP on the command line and PHP serving web pages can have different settings, so a check run over SSH does not always reflect what visitors get.
The settings worth asking about
You will rarely change these yourself, and on shared hosting you usually cannot. It still helps to know what they are, so you can understand a host’s answer or a developer’s suggestion.
| Setting | What it controls | When it matters |
|---|---|---|
| opcache.enable | Whether the opcode cache is on for web requests | Always. It should be on. |
| opcache.memory_consumption | How much memory holds compiled code | Large sites with many plugins can fill it |
| opcache.max_accelerated_files | How many separate files can be cached | Sites with big plugin collections or several WordPress installs on one server |
| opcache.interned_strings_buffer | Memory for repeated text values in code | Usually fine; hosts tune it with the memory setting |
| opcache.validate_timestamps | Whether PHP checks files for changes | Matters if you edit files on the live server |
| opcache.revalidate_freq | How often, in seconds, files are checked | Affects how quickly edits take effect |
The defaults suit a small site. The two that most often need raising on larger setups are the memory and the file count. A good host monitors whether the cache is full. If yours does not, ask whether they can tell you how full it is.
When code changes do not seem to take effect
This is the side effect that catches people out. You edit functions.php over FTP, or upload a fixed plugin file, and the site behaves exactly as before. Ten minutes later it suddenly changes.
What happened is that OPcache was still running the compiled copy of the old file. Whether and how quickly PHP notices a changed file depends on the two validation settings in the table. Many hosts check every few seconds. Some, for speed, check rarely or never, and rely on a reset after deployments.
If a change you made directly to a PHP file is not showing up:
- Wait a minute and try again, logged out and with any page cache cleared.
- Look for an OPcache reset or “restart PHP” option in the hosting panel.
- Ask the host to reset OPcache for your account if neither works.
This is different from content changes not appearing, which is almost always a page, browser or CDN cache. If you only changed a page in the editor, OPcache is not involved.
A related oddity: a plugin update can, rarely, leave a site briefly mixing old and new compiled files. If the site shows errors straight after an update and they clear up on their own a minute later, this is a likely explanation. If errors persist, it is a real problem with the update rather than with OPcache.
OPcache and your PHP version
Each newer PHP release has tended to run WordPress more efficiently, and OPcache comes along with every version. PHP 8 also added a JIT compiler that works through OPcache. For typical WordPress pages, which spend much of their time waiting on the database and building HTML, the JIT makes little practical difference, and it is often left switched off. Upgrading PHP itself is the bigger decision, with compatibility risks of its own, covered in our post on what can break when you update PHP.
Where OPcache fits in a speed check
On a slow site, confirming OPcache is on is a two-minute check that rules out one cause. If server response time is still slow for uncached pages after that, the cause is somewhere else: slow queries, external calls made while the page builds, too little CPU, or too few PHP workers. Our post on reducing slow server response time works through those in order. For the wider picture, our full guide to website speed shows how server-side fixes sit next to images, code and third-party scripts.
Frequently asked questions
Can I install OPcache myself on shared hosting?
Usually you cannot install it, but you rarely need to. It is part of PHP and most hosts enable it for every account. Some control panels let you tick it in a list of PHP extensions. If it is missing and the panel has no option, ask the host, because the settings are controlled at server level.
Will enabling OPcache improve my PageSpeed score?
It may improve server response time on pages that are not page cached, which can show up in lab tests. On a site where the speed test hits a page cache, the score may not change at all. The benefit shows most for logged-in users, shoppers, the admin area and AJAX requests.
Is there a WordPress plugin for OPcache?
There are plugins that show OPcache status and let an administrator reset it, which can be handy on a VPS. They do not create the cache, which lives inside PHP. On shared hosting, reset options may be disabled by the host, so a plugin may only be able to report what it sees.
Does OPcache need clearing after every WordPress update?
Normally not. Most hosts configure PHP to notice changed files within seconds, so updates take effect on their own. On servers set to check files rarely, a reset after updates is part of the routine, and the host or developer who set it up that way should be doing it.
Slow uncached pages can come from the server, PHP or the site itself, and it is rarely obvious which. A speed optimisation review looks at server response time alongside the front end and separates what you can fix from what needs your host.
Next in this series: How to Choose a WordPress Caching Plugin for Your Server