Table of Contents
PHP OPcache stores compiled PHP instructions in shared memory so the web server’s PHP runtime can reuse them across requests. It saves the work of parsing and compiling the same scripts repeatedly. It helps most when a site runs substantial PHP code on every request.

What OPcache speeds up
When PHP first loads a script, it compiles it into instructions called opcodes. OPcache keeps that compiled copy available for later requests. PHP still executes the script each time. If database queries, an external API, or image processing dominates response time, OPcache alone will have limited impact.
A full-page cache stores the finished response. An object cache can store results that PHP would otherwise fetch or compute again. These solve different problems and can be used alongside OPcache.
Enable and verify OPcache
- Run
php -vto see whether Zend OPcache is loaded in command-line PHP. The website may use another PHP version or configuration, so check the PHP handler for the site in your hosting panel or server configuration. - Load the extension if the web runtime does not already have it. Use the hosting panel or the package for your PHP version. In the configuration used by that runtime, set
opcache.enable=1. The PHP installation guide covers loading the extension when required. - Reload the PHP service that runs the site, such as PHP-FPM, through your normal service controls. On managed hosting, use the provider’s PHP configuration controls.
- Verify the web runtime with your hosting panel or a private diagnostic that calls
opcache_get_status(false). Once the site has served traffic, check that the cache is enabled and is storing scripts. Keep diagnostics off public pages.
If you use DirectAdmin
Check which PHP version and handler the site uses before changing CustomBuild settings. On a server you administer, use the OPcache option in CustomBuild and follow the apply or rebuild procedure for that PHP handler. Verify the result through the website’s PHP runtime. A command-line check alone can show OPcache for a different PHP installation.
Prevent stale code and tune by measurement
- Keep
opcache.validate_timestamps=1unless your deployment process reliably refreshes the cache for the web runtime. If timestamp checking is off, old compiled code can remain active after files change. - Check cache memory usage, cached script counts, and whether the cache is full before raising
opcache.memory_consumptionoropcache.max_accelerated_files. - Compare server response times under similar traffic with the cache warmed up. Investigate database or application bottlenecks separately.
See the PHP OPcache configuration reference for each setting’s behavior.
Reader Comments 0
Sign in with email or Google to join the discussion.