PHP OPcache
Before PHP can run a file, it reads it and translates it into instructions it can execute. OPcache keeps these translated instructions in memory, so the next request can use them right away instead of translating the same files again.
Why it matters
Section titled “Why it matters”WordPress, the theme and the plugins consist of hundreds of PHP files, and many of them are loaded for every page that isn’t served from a page cache. Without OPcache, PHP translates all of them on every request, which costs time and processor power. With OPcache, that step happens once, and every following request saves it.
OPcache isn’t a page cache. WordPress still runs its code and asks the database for content on every request; OPcache only saves the translation step.
What influences it
Section titled “What influences it”Server: Whether OPcache is loaded and enabled is up to the hosting provider; most enable it. The size matters too: OPcache has a fixed amount of memory and a maximum number of files. When a site with many plugins needs more, files drop out and are translated again. A restart of PHP empties the cache, and it fills up again with the next requests.
WordPress: The more plugins and the larger the theme, the more files OPcache has to hold. After an update, OPcache notices the changed files and translates them again.
In Permo
Section titled “In Permo”The OPcache card is in System info, tab Server & System, under PHP. While OPcache is on, it shows how much of its memory is in use, as a share and as a bar with the amounts.
- Green up to 90% in use.
- Red above 90%, with Almost full, and from 99% with Full: new files aren’t cached. Files already in the cache stay; new or changed ones are compiled on every request.
- Red with Off when OPcache isn’t running: PHP compiles every file on every request.
- On in green, without a bar, when OPcache runs but the server doesn’t let PHP read how full it is.
Space taken by old copies of changed files counts as in use, because OPcache frees it only when it restarts.
Related
Section titled “Related”Sources
- PHP: OPcache, accessed
- PHP: OPcache runtime configuration, accessed