Quickstart cipi.yml Web panel API MCP Ecosystem Guides Docs GitHub Telegram channel
  1. Home
  2. Guides
  3. PHP OPcache on a server with many apps: size it, watch it, keep apps apart
Operations

PHP OPcache on a server with many apps: size it, watch it, keep apps apart

Why one OPcache serves every app on a PHP version, what happens when it fills up after a few deploys, how Cipi sizes it for the server's RAM and warns before it is full, and the setting that stops one app from loading another's cached files.

By Updated 5 min read

OPcache keeps the compiled form of PHP files in memory, so PHP doesn't parse them at every request. On a laptop it is a detail. On a server that hosts ten apps, it is one shared piece of memory — and two things about it matter: what happens when it is full, and who may read what is in it.

Key ideas, in plain words#

TermMeaning
OPcachePHP's cache of compiled scripts, in memory
PHP-FPMThe service that runs PHP for websites. One per PHP version on the server
PoolThe PHP processes of one app, running as that app's Linux user
SharedEvery pool of a PHP-FPM uses the same OPcache: all the apps on PHP 8.4 share one cache
  • PHP-FPM 8.4one OPcache, sized for the server's RAM
  • Pool "shop"Laravel, runs as shop
  • Pool "blog"WordPress, runs as blog
  • Pool "billing"Symfony, runs as billing

1. Look at it#

bash
sudo cipi php opcache
bash
OPcache — PHP 8.4  one cache for every app on PHP 8.4
  Sized      384 MB (by Cipi, for the RAM), strings 48 MB (by Cipi, for the RAM), 65407 files (by Cipi, for the RAM)
  Memory     180.4 MB of 384.0 MB used (47.9% with 4.0 MB wasted)
  Strings    20.0 MB of 48.0 MB
  Files      8412 cached — 9950 keys of 65407 (15.2%)
  Found      99.8% of the requests for a script — restarted for room: 0 (memory), 0 (files)
  Room left
LineRead it as
MemoryHow much of the ceiling the compiled code takes. Wasted is code of files that changed or went away
FilesHow many scripts are cached, against the most it may hold
FoundThe share of requests for a script that found it compiled. Under 95% on a busy server means work at every request
Restarted for roomPHP emptied the whole cache because it was full. More than zero: give it more room
The last lineRoom left, Nearly full (over 90%) or Full — with the command to run

Cipi asks PHP-FPM itself (the php command has a cache of its own), and the answer is numbers only — never which scripts are cached. --json for scripts, sudo cipi php opcache 8.4 for one version.

2. Why it fills up#

A cache holds the code of every app on that PHP — and of every release. Each deploy is a new folder, so its files enter the cache under new names while the old ones stay until PHP notices they are gone. Ten apps that deploy a few times a day fill a small cache in days.

A full OPcache says nothing on its own. PHP keeps serving, but every file that doesn't fit is compiled at every request — for every app on that version. Pages get slower, CPU climbs, nothing appears in a log. That is why Cipi:

Sizes it for the RAMWhen PHP is installed: 128 MB under 2 GB of RAM, 192 MB at 2 GB, 256 MB at 4 GB, 384 MB at 8 GB, 512 MB from 16 GB — with strings and file slots to match
Watches itThe monitor checks each cache and sends monitor_opcache when one is full — to e-mail, Slack, Telegram or wherever your alerts go — and a recovery when it has room again
Says what to dosudo cipi php opcache prints the cipi ini set that gives it room

3. Give it more room#

After the server was resized — more RAM, same PHP — let Cipi size it again:

bash
sudo cipi php opcache tune

Or set a size of your own for one version, which wins over Cipi's and stays through updates:

bash
sudo cipi ini set opcache.memory_consumption=768 --php=8.4
sudo cipi ini set opcache.max_accelerated_files=130987 --php=8.4
sudo cipi ini list                  # who set each value: Cipi, you, or PHP
sudo cipi ini unset opcache.memory_consumption --php=8.4   # back to Cipi's

Both restart that version's PHP-FPM — tested first, and left as it was if it refuses. A restart empties the cache; it refills in seconds as pages are visited. Pick a quiet minute.

SignalDo
Nearly full after a week of deploystune, or a size of your own one step up
Restarted for room above zeroMore memory: it has been emptying itself
Many apps on one version, most idleFine: the ceiling isn't reserved, only what is cached is used
One heavy app (Magento, a big monolith)Put it on Octane if it is Laravel — a cache of its own — or on a PHP version of its own

4. Keep apps apart#

The second thing about a shared cache: PHP gives a cached script without opening the file. So neither open_basedir nor the permissions on another app's home are asked — and one pool could include a file another app had cached: its wp-config.php, its bootstrap/cache/config.php, with every password in it. It can't read those files on disk; from the cache, it could.

PHP has the check, and ships with it off. Cipi turns it on for every PHP-FPM:

ini
; /etc/php/8.4/fpm/conf.d/90-cipi-opcache.ini
opcache.validate_permission = 1

A cached script is given only to a pool whose user may read the file. An app that reads its own files sees no difference; an app that was broken into, or a tenant's code, gets nothing of the others. sudo cipi php opcache says, for each PHP-FPM, whether it runs with the check.

Still sharedWhy it is left as is
opcache_get_status(true) lists the scripts of every app on that versionopcache.restrict_api would hide it, and breaks tools that call it — your choice, per server
opcache_reset() empties the cache of every app on that versionThe same setting. A deploy on Cipi never needs a reset
Octane appsNot shared at all: each runs a PHP, and a cache, of its own

5. Deploys and OPcache#

Nothing to do after a deploy. Cipi's sites pass PHP the real path of the release (…/releases/42/public/index.php, never …/current/…), so:

  • a request that started on release 41 finishes on 41 — PHP never mixes two releases;
  • release 42's files are new names: they are compiled at their first request;
  • old releases' scripts age out of the cache.

No opcache_reset(), no PHP-FPM reload, no opcache.validate_timestamps tricks. The one cost is room — which is what step 3 is for.

Troubleshooting#

ProblemFix
Slower after many deploys, nothing in the logssudo cipi php opcache: a full cache compiles at every request. More room, step 3
Found low right after a restartNormal: the cache refills as pages are visited
A version shows no numbersIts PHP-FPM is not running: sudo cipi service list, then sudo cipi service restart php
A plugin says OPcache is offIt asked the php command, which has its own cache settings. The sites' PHP-FPM is what counts: sudo cipi php opcache
A value you set is ignoredAnother layer sets it later: sudo cipi ini list shows which, and from where

The reference: PHP — OPcache.

Questions

Do I need to do anything?

Usually not: Cipi sizes OPcache for the server's RAM when PHP is installed, turns the permission check on, and the monitor warns when a cache is full. Look at sudo cipi php opcache after resizing the server or adding many apps.

Does a bigger OPcache use more RAM?

Only as code fills it. The size is a ceiling, taken from the RAM as scripts are cached, not reserved when PHP starts.

Why does it fill up with deploys?

Each release is a new folder, so its files enter the cache under new names; the old ones stay until PHP notices they are gone. Many deploys a day on many apps add up.

Should I reset OPcache after every deploy?

No. On Cipi each request runs the files of one release, by their real path: new files are compiled at their first request, nothing stale is served. A reset would empty the cache of every app on that PHP at once.

What about Octane apps?

An Octane app runs a PHP of its own, with a cache of its own: none of this is shared with the other apps.

Is the JIT the same thing?

No. The JIT compiles hot code further, per app if you want it: sudo cipi app jit shop on. OPcache is always on.

Try it on your own server

Free and open source. One command on a fresh Ubuntu 24.04 or 26.04 VPS.

wget -O - https://cipi.sh/setup.sh | bash
Read the quickstart