Skip to main content

OPcache

Updated: October 30, 2026
By Willya Randika

OPcache is a built-in PHP extension that stores compiled bytecode in server memory. Without it, every request makes PHP re-read the .php file, parse it into bytecode, and throw the result away. With it, parsing and compiling happen once, and later requests run the stored bytecode directly. OPcache holds bytecode, not finished HTML and not database rows, so it sits at a different layer from a Web Cache or an Object Cache. It makes each PHP process cheaper, and it runs under PHP-FPM or any other handler.

The settings worth knowing

opcache.enable turns the feature on or off. opcache.memory_consumption sets how much RAM holds bytecode; an undersized pool evicts entries constantly and the benefit disappears. opcache.max_accelerated_files caps how many files can be cached, and applications with many files need that number raised. opcache.validate_timestamps decides whether OPcache checks for changed files, and opcache.revalidate_freq sets how often that check runs.

What goes stale on deploy

While validate_timestamps is on, OPcache compares a file's change time on the revalidate_freq interval and recompiles files that changed. In development, leave the check on so edits show up right away. In production many people turn it off to avoid the file-stat cost entirely, then reset the cache by hand on each deploy. The consequence is explicit: with opcache.validate_timestamps=0, OPcache never looks at the files, so new code stays unused until the cache is cleared.

Checking and clearing

Confirm the extension is live with php -i | grep opcache.enable or phpinfo(); if no opcache section appears, it is off. After a deploy, clear the cache through a panel button, the opcache_reset() function, or a reload of PHP-FPM. systemctl reload php-fpm generally empties the stored bytecode.

Stale bytecode that keeps running

The real trap appears when a file is replaced outside the normal deploy path, with rsync, a git checkout, or FTP, while validate_timestamps is off. The file's change time moves but OPcache never checks it, so PHP keeps running the old bytecode. Your site looks broken even though the files on disk are correct. Every out-of-band file change therefore needs a cache reset. If you are unsure whether OPcache or a CDN is serving the old version, test at the server first: OPcache is a local cache, not one sitting in the network.

FAQ

Does OPcache store page HTML?

No. OPcache stores compiled PHP bytecode, not page output. A page cache is still what removes a request from PHP entirely.

What is the difference between revalidate_freq and validate_timestamps?

validate_timestamps decides whether OPcache checks changed files at all; revalidate_freq decides how often that check runs. With validate_timestamps off, revalidate_freq has no effect.

Do I have to restart PHP-FPM after a deploy?

Not always. Clearing OPcache is enough to force recompiling. A reload or restart of FPM is just one way to empty the bytecode cache.

Disclaimer: Hosting Wiki articles are prepared for educational and reference purposes. Hosting technology keeps evolving, so some technical details may change over time.