How to flush the PHP OPcache
PHP's OPcache stores compiled PHP as bytecode in memory so it does not recompile your code on every request. That speeds up the site, but it also means that after you change PHP files the cache can keep serving the old code until it is refreshed.
Flush it with the TurboStack CLI
Connect over SSH and run:
tscli opcache clear
This resets the OPcache for the site's PHP-FPM, so the next requests recompile from your current files.
When you need it
-
After deploying or editing PHP files outside the normal publish flow, when your changes do not show up.
-
On sites tuned for production, where OPcache does not re-check file timestamps on every request (
validate_timestampsoff) for maximum performance - there, a flush is required to pick up new code.
Note
Right after a flush the first requests are a little slower while PHP recompiles; this settles within
moments. If you use OPcache preloading (php_opcache_preload_script), changing the preloaded
code needs a PHP-FPM reload, not just a cache flush - see Configure PHP.
Related
- Configure PHP
- Switch PHP version
- Override PHP settings
- Why is my site slow?
- TurboStack CLI -
tscli opcache clear