How to Control OPcache With xCloud

Updated November 7, 2026 · 7 min read

Summarize with:
Share:

OPcache keeps compiled PHP code in memory, so PHP does not read and compile the same files on every request. xCloud turns OPcache on for every PHP version it installs and starts it with larger limits than PHP’s own defaults. This guide shows where to switch it on or off, how to change its settings, how to tell whether the cache is big enough, and when Auto-tune helps.

One OPcache per PHP version. The OPcache settings are saved for a PHP version on a server, not for one site. Every site on that server that runs the same PHP version uses the same settings, and on Nginx servers they share one cache in memory. Keep this in mind when you size the cache for a server with many sites.

xCloud’s OPcache defaults

xCloud writes these values when it installs a PHP version. PHP’s own defaults are shown for comparison (from the PHP OPcache configuration reference).

Setting in xCloud PHP setting xCloud default PHP default
OPcache opcache.enable On On
Memory Consumption opcache.memory_consumption 512 MB 128 MB
Interned Strings Buffer opcache.interned_strings_buffer 32 MB 8 MB
Max Accelerated Files opcache.max_accelerated_files 100000 10000
Revalidate Frequency opcache.revalidate_freq 60 seconds 2 seconds

Revalidate Frequency is how often OPcache checks whether a PHP file changed. At 60 seconds, a file you edit or deploy can take up to a minute to show up.

Step 1: Turn OPcache on or off for a PHP version

Open your server and go to ‘Management’ → ‘Manage PHP’. The ‘PHP Configuration’ tab lists every PHP version, and the ‘OPCache’ column has a switch for each installed version. Click the switch and confirm to turn OPcache on or off for that version.

The OPCache switch for an installed PHP version in Server → Management → Manage PHP

The switch changes every site on the server that runs that PHP version. Leave it on unless you are troubleshooting a problem that OPcache causes.

Step 2: Open the OPcache settings

Open a site that runs the PHP version you want to tune and go to ‘Site Settings’. In the ‘PHP Configurations’ box, find ‘OPcache settings’ and click ‘Edit’.

The Edit button next to ‘OPcache settings’ in Site → Site Settings → PHP Configurations

The ‘Manage OPcache Configurations’ popup opens. The ‘PHP Version’ field shows which version you are changing. Every site on this server that uses that version gets the new values.

The Manage OPcache Configurations popup with the PHP version and the four OPcache settings

Step 3: Change the values and save

Set the four values:

  • Memory Consumption: the memory OPcache uses to store compiled code, in MB.
  • Interned Strings Buffer: the memory for repeated strings (class names, function names), in MB.
  • Max Accelerated Files: how many PHP files OPcache can hold.
  • Revalidate Frequency: how often OPcache checks for changed files, in seconds. 0 means it checks on every request.

Click ‘Save Settings’. xCloud writes the values to that PHP version’s configuration and restarts PHP for that version (PHP-FPM on Nginx servers, LiteSpeed on OpenLiteSpeed servers). Requests can pause for a moment during the restart, so save at a quiet time.

If saving fails, check that the server shows Connected and try again. The values only change after a successful save.

Step 4: Let Auto-tune pick the values (optional)

If you are not sure what to set, click ‘✨ Auto-tune’ in the popup. xCloud reads the server’s RAM and fills in suggested values. Review them, then click ‘Save Settings’ to apply them. Nothing changes until you save.

Auto-tune filled in suggested OPcache values based on the server’s RAM

Auto-tune picks these values:

Server RAM Memory Consumption Interned Strings Buffer Max Accelerated Files Revalidate Frequency
2 GB or less 128 MB 8 MB 100000 60 seconds
More than 2 GB, up to 8 GB 256 MB 16 MB 100000 60 seconds
More than 8 GB 512 MB 32 MB 100000 60 seconds

Use Auto-tune on a small server where the 512 MB default takes too much of the RAM. On a server with many sites on one PHP version, the suggestion can be too small: check the hit rate (below) before and after you change it.

Size OPcache for many sites on one PHP version

All sites on one PHP version share its OPcache, so the cache has to hold the PHP files of all of them. A WordPress site with a page builder, WooCommerce and a few dozen plugins can load thousands of PHP files. Ten such sites on PHP 8.3 need room for all of those files at once.

When the cache is too small, two things happen:

  • Memory runs out. OPcache stops caching new files, and when too much memory is wasted it clears the whole cache and starts over. Pages get slower while it fills up again.
  • The file limit is reached. Once OPcache holds as many files as Max Accelerated Files allows, new files are not cached and PHP compiles them on every request.

Both show up as a low hit rate. Raise Memory Consumption when free memory is near zero or the cache restarted because memory was full. Raise Max Accelerated Files when the number of cached files is close to the limit.

Check the hit rate and whether the cache is full

The hit rate is the share of requests OPcache served from memory. On a warmed-up site it should be close to 100%. You check it from PHP running behind your website, not from the command line: PHP on the command line has its own OPcache (usually switched off), so php -r does not show your sites’ cache.

  1. Connect to the server over SSH as the site user, or open the web terminal.
  2. Create a file with a hard-to-guess name in the site’s web root, for example opcache-check-7f3k2.php:
<?php
header('Content-Type: text/plain');
$s = opcache_get_status(false);
if (!$s) { exit("OPcache is off for this PHP version\n"); }
$m = $s['memory_usage'];
$st = $s['opcache_statistics'];
printf("Hit rate: %.1f%%\n", $st['opcache_hit_rate']);
printf("Memory used: %d MB, free: %d MB\n", $m['used_memory'] / 1048576, $m['free_memory'] / 1048576);
printf("Cache full: %s\n", $s['cache_full'] ? 'yes' : 'no');
printf("Cached files: %d of %d\n", $st['num_cached_scripts'], $st['max_cached_keys']);
printf("Restarts because memory was full: %d\n", $st['oom_restarts']);
printf("Restarts because the file limit was full: %d\n", $st['hash_restarts']);
  1. Open https://yoursite.com/opcache-check-7f3k2.php in your browser.
  2. Delete the file when you are done. It shows details about your server that should not stay public.

Read the result like this:

What you see What it means What to change
Free memory near 0, Cache full: yes, or memory restarts above 0 The cache is too small for all the sites on this PHP version Raise Memory Consumption
Cached files close to the limit, or file-limit restarts above 0 Too many PHP files for the limit Raise Max Accelerated Files
Hit rate well below 100% a while after a restart The cache keeps losing files Check the two rows above

The second number in “Cached files” is usually a bit higher than your Max Accelerated Files value (for example 130987 for 100000), because PHP rounds the limit up internally.

The numbers start from zero after every PHP restart, so check them after the sites have had normal traffic for a while. A WordPress plugin that shows OPcache status works too, as long as it runs on the site and not on the command line.

Tip: give a busy site its own PHP version

Each PHP version has its own OPcache. If one busy site fills the cache, you can move it to a PHP version no other site on the server uses, so it gets a cache of its own. Change the site’s PHP version under ‘Site Settings’ → ‘PHP Configurations’ → ‘PHP Version’ (see how to change a site’s PHP version) and test it on a staging site first if the site runs old plugins.

The trade-off:

  • More memory. Each PHP version reserves its own OPcache memory and runs its own PHP service.
  • More to maintain. You have one more PHP version to keep updated, and its settings are separate from the others.

Frequently asked questions

Do the OPcache settings on a site’s settings page change only that site?

No. The OPcache settings are saved for the site’s PHP version on that server, so they apply to every site on the server that uses the same PHP version. The popup shows which version you are changing under ‘PHP Version’.

Does saving OPcache settings cause downtime?

Saving restarts PHP for that version (PHP-FPM on Nginx servers, LiteSpeed on OpenLiteSpeed servers), so requests can pause for a moment. Change the settings at a quiet time, and don’t switch OPcache off and on again just to refresh a status.

Why don’t my PHP file changes show up right away?

xCloud sets ‘Revalidate Frequency’ to 60 seconds, so OPcache checks a changed PHP file at most once a minute. Wait a minute, or set it to 0 while you develop and back to 60 when you are done.

Should I give a busy site its own PHP version?

You can. Each PHP version has its own OPcache, so a busy site on its own version stops competing with the other sites for cache space. The trade-off is more server memory and one more PHP version to keep updated.

If you run into any issues, feel free to reach out to our support team.