TL;DR
PHP OPcache speeds up WordPress by storing pre-compiled script bytecode in shared memory, so your server doesn’t have to reload PHP files on every single request. It’s server-side optimization for generating pages, while solutions like NitroPack handle delivering those pages to users with front-end optimizations and CDN.
WordPress is dynamic, which is great for flexibility but rough on performance.
Every time someone visits your site, your server scrambles to find PHP scripts, compile them into machine-readable code, and execute them. It’s resource-intensive and slow, especially when you’re running a dozen plugins and a feature-rich theme.
This is where caching comes in. But not all caching is created equal.
PHP OPcache addresses the root cause: the compilation bottleneck. Instead of recompiling scripts for every single visitor, OPcache does it once, stores the result in memory, and serves it instantly on subsequent requests.
That means Lower CPU usage, faster response times, and a server that can handle more traffic without breaking a sweat.
Let’s take a look at how it actually works.
What is PHP OPcache?
PHP OPcache is an opcode cache that stores the results of PHP’s compilation process.
Normally, PHP reads your code, translates it into bytecode (the language your server understands), and then executes it. OPcache skips the first two steps by storing that compiled bytecode in memory. If a new request comes in, your server simply grabs the pre-compiled version and runs it immediately.
Will OPcache speed up WordPress?
Yes, but specifically for Time to First Byte (TTFB), which is how long your server takes to start sending data back to browsers.
That means OPcache won’t fix slow-loading images or render-blocking CSS (that’s where tools like NitroPack come in). What it does do is make your server faster at processing PHP requests.
Where OPcache really matters
Page caching plugins work great for public pages, but they can’t cache everything. That means you’ll need OPcache for things like:
- WordPress Admin dashboard
- WooCommerce checkout pages
- Logged-in user experiences
- The initial “cache miss” before a page gets cached
That’s because these dynamic requests have to run PHP.
OPcache ensures that code runs efficiently, significantly reducing CPU usage, and allows your server to handle more concurrent visitors without requiring additional hardware.
How does PHP OPcache work?
The best way to understand OPcache is to see what happens with and without it.
Without OPcache: The slow way
Every single request follows this three-step process:
- Read code → Server finds the PHP file on disk
- Compile to bytecode → PHP translates human-readable code into machine instructions
- Execute → Server runs the compiled code and generates your page
This happens every single time. Same file, same code, same compilation step—repeated thousands of times a day.
With OPcache: The fast way
The first request still follows all three steps. But here’s where it gets interesting:
- Read code → Server finds the PHP file
- Compile to bytecode → PHP translates it once
- Save to Shared Memory → OPcache saves the compiled version
- Execute → Server runs the code
On the second request (and every request after):
- Read from Shared Memory → OPcache already has the compiled version
- Execute → Server runs it immediately
No reading files from disk. No compilation. Just execution.
The compiled code sits in shared memory, which means it’s accessible to all server processes simultaneously.
When User A visits your homepage, OPcache compiles and stores it. When User B visits 10 seconds later, they benefit from the work already done for User A. It’s not a per-user cache, it’s a server-wide optimization that accelerates PHP for everyone.
How to install OPcache on your server
Good news: If you’re running PHP 5.5 or newer, OPcache is already installed. You just need to enable it.
Run this command in your terminal: php -v
If you see “with Zend OPcache” in the output, you’re good to go.
Configuration: The settings that matter
Open your php.ini file (usually in /etc/php/8.x/fpm/php.ini or /etc/php/8.x/apache2/php.ini) and adjust these:
opcache.memory_consumption=128: Memory allocated (in MB).opcache.max_accelerated_files=10000: Max files to cache. Set it to20000instead for heavier sites, like those running WooCommerce, page builders, and a large plugin stack.opcache.revalidate_freq=60: How often to check for updates (seconds).
Pro tip: After changing these settings, you must restart your web server and PHP-FPM for changes to take effect:
sudo systemctl restart php8.x-fpm
sudo systemctl restart nginx # or apache2 How OPcache, page caching, and CDNs work together
You’ve optimized PHP execution—great. But your site still needs to deliver images, CSS, JavaScript, and HTML to users.
That’s where the confusion starts.
Many people think enabling OPcache means they don’t need page caching or a CDN. Others assume page caching makes OPcache redundant. Both are wrong.
These tools work at completely different layers of your performance stack, and you need all of them for maximum speed:
- Layer 1 (Deepest): OPcache speeds up PHP code execution on your server. Matters for every single PHP request, including admin areas and logged-in users.
- Layer 2 (Middle): Object Cache (Redis/Memcached) stores database query results in memory. Optimizes the time it takes to fetch posts, user data, or plugin settings.
- Layer 3 (Surface): Page Caching + CDN stores complete HTML pages and delivers them from edge servers globally. Works for anonymous visitors viewing public pages.
🙂 Important
Before OPcache, developers relied on third-party extensions like APC and Xcache for this foundational layer. These are now abandoned—OPcache has been bundled directly into PHP since version 5.5, maintained by the core PHP team with regular security updates. If you spot legacy APC references in old configurations, it’s safe to remove them.
What to do after OPcache setup
You’ve now optimized your server’s performance for executing PHP code. That’s a solid foundation—but it’s only one piece of the puzzle.
Your server is faster at generating pages, but you still need to optimize the assets themselves (images, CSS, JavaScript) and how they’re delivered to users worldwide.
This is where NitroPack completes your performance stack.
NitroPack operates at Layer 3, handling what happens after your server generates a page.
While OPcache makes your server efficient at generating pages, NitroPack handles the front-end optimization:
- Image optimization: Automatic WebP conversion, adaptive sizing for different devices, and lazy loading
- Code minification: Compresses HTML, CSS, and JavaScript files
- Critical CSS generation: Inlines only the CSS needed to render above-the-fold content
- Global CDN delivery: The Content Delivery Network serves optimized content from edge servers worldwide
- Smart cache invalidation: Refreshes only affected pages when content changes
All these heavy optimization tasks run on NitroPack’s servers, so your hosting doesn’t take the performance hit. NitroPack’s “Ludicrous mode” works in tandem with a healthy server environment, such as the one you’ve just created with OPcache. While OPcache handles PHP execution, NitroPack handles everything else and processes it on its cloud infrastructure.
The result? Maximum Core Web Vitals scores without the manual configuration headache.
Your backend is optimized. Now optimize your frontend.
And if you ever need help, our support team boasts a sub-2-minute response time and a 30-minute average resolution time.
Test NitroPack yourself
Cache miss vs. cache hit: Who does what?
OPcache handles the “cache miss” (generation), while NitroPack handles the “cache hit” (delivery).
When your page cache expires, or someone hits an uncached page, OPcache prevents that request from being slow. When the cache is hot, NitroPack ensures visitors get instant load times from the nearest edge server.
And for areas that page caching intentionally skips—like the WordPress admin, WooCommerce checkout, or logged-in user experiences—OPcache is the only thing keeping them fast.
You need both.
Get started with OPcache
PHP OPcache is server-side optimization at its best—simple to enable, immediately effective, and completely free.
It speeds up PHP execution, reduces CPU usage, and ensures your backend stays responsive even under heavy traffic. But remember: OPcache handles page generation, not delivery.
For complete WordPress performance, you need both backend and frontend optimization. OPcache takes care of the first part. NitroPack handles the second.
Enable OPcache, configure it properly, then layer in the rest of your performance stack for maximum speed.
Test NitroPack yourself
Frequently Asked Questions (FAQs)
Should I enable OPcache?
Yes. It’s a standard best practice for any PHP environment. If you’re running PHP 5.5 or later, there’s no reason not to enable it. The performance gains are immediate, and the risk is minimal.
Do I need APCu if I have OPcache?
It depends on your application. OPcache handles bytecode caching (which you should always have enabled), but if your app needs to cache custom data like query results or session data in memory, then yes, you’d benefit from adding APCu. They serve different purposes and work well together.
Will OPcache improve my PageSpeed score?
Partially. OPcache improves Time to First Byte (TTFB), which helps your Largest Contentful Paint (LCP) score. But it won’t fix frontend issues like unoptimized images, render-blocking CSS, or large JavaScript bundles. That’s where solutions like NitroPack come in—they handle the front-end optimizations that PageSpeed actually measures.