jsonLd && ( ) Skip to content
All posts

A Big WordPress Store Was Slow Because OPcache Was Full

A large WooCommerce store took about 2.5 seconds per uncached page with every cache on. OPcache was full, and three settings brought it to 0.35 seconds.

In June one of the WooCommerce stores we host was slow on every page that could not come from the cache. Logged-in pages, the cart and the checkout took about 2.5 seconds to render, and the CPU of the site stayed at its limit for most of the day.

The store is large, with about 30,000 PHP files from WordPress, WooCommerce, a multilingual plugin, a heavy theme and 61 plugins in total. Its page cache and object cache both worked, so we first looked at the database and at the plugins, but neither explained the slow pages.

The cause was OPcache, which had run out of space. After we raised three settings, the same pages rendered in about 0.35 seconds and the CPU was close to idle.

What OPcache does

PHP turns every PHP file into bytecode before it runs it. OPcache keeps that bytecode in shared memory, so the next request can skip the compile step and run the stored copy.

On a site that fits in OPcache, every file is compiled once and then served from memory until PHP restarts.

Why is a big WordPress site slow when the page cache and object cache are both on?

A page cache only helps visitors who get a stored copy of a page. Carts, checkouts, account pages and the admin always run PHP, and on a WooCommerce store those are the requests that matter most, which is also why bots that fill carts hurt so much.

An object cache saves database queries, but it does nothing for the time PHP spends compiling code. On this store most of the time went into compiling, because OPcache was full.

When OPcache is full, it stops caching new files, so PHP compiles them again on every request. Files that change leave wasted space behind, and once enough of it builds up, OPcache restarts and throws away everything it holds.

The store had 128 MB for OPcache and room for 10,000 files, which are also the PHP defaults (PHP manual, as of October 2026). PHP rounds the file limit up to 16,229, which is still far below 30,000 files.

How do I check whether OPcache is full?

The command line has its own OPcache, which is usually switched off, so php -r does not show what your website uses. Ask the web server instead, with a small file that you delete afterwards:

<?php
header('Content-Type: text/plain');
$s = opcache_get_status(false);
if (!$s) {
    exit("OPcache is off, or its status is restricted\n");
}
print_r([
    'cache_full'      => $s['cache_full'],
    'free_memory_mb'  => round($s['memory_usage']['free_memory'] / 1048576),
    'cached_scripts'  => $s['opcache_statistics']['num_cached_scripts'],
    'max_cached_keys' => $s['opcache_statistics']['max_cached_keys'],
    'oom_restarts'    => $s['opcache_statistics']['oom_restarts'],
    'hash_restarts'   => $s['opcache_statistics']['hash_restarts'],
]);

Save it under a random name in the site root, open it in the browser and then delete it, because it shows details of your server to anyone who finds it.

OPcache is too small when cache_full is 1, when free memory is close to zero after a busy day, or when the restart counts keep going up. On this store OPcache had 24 bytes of free memory left.

To see how many files OPcache needs room for, count the PHP files of the site:

find /path/to/site -name '*.php' | wc -l

What we changed

These are the three settings that decide how much OPcache can hold, with the values we gave the store:

opcache.memory_consumption = 256
opcache.interned_strings_buffer = 32
opcache.max_accelerated_files = 50000

The first is the memory for bytecode in MB. The second is memory in MB for strings that repeat across files, such as class and function names, and large plugin sets fill it quickly. The third is the number of files, which PHP rounds up to 65,407.

A larger OPcache uses more memory, but the total memory use of the store went down. Requests finished about seven times faster, so far fewer of them ran at the same time.

These are now the OPcache settings on our Spark+ plan and above. On other hosts you set them in php.ini or on a PHP settings page, because .user.ini files and ini_set() cannot change them, and PHP has to restart before they apply.

If your site has more PHP files than OPcache has room for, set opcache.max_accelerated_files above that count and give opcache.memory_consumption enough room that free memory stays well above zero after a busy day.

Related update: OPcache Restart Monitoring & Per-Tier Scaling