Examples of pre-warming the opcache on PHP 8.5, for:
- Linux based containers, i.e. Docker
- Application code is read-only after container build
These examples are primarily for Google Cloud's App Engine, which builds Docker containers using buildpacks, which include all application code that remains read-only at runtime.
- Basic example with single
public/index.php
file. - Intermediate example using Symfony's Finder to compile all project files.
The opcache file based cache is only valid for the same build of PHP (not just a specific version match), so it's important that the opcache is generated at deploy / container build time with the exact same build of PHP.
This is due to zend_system_id
being included in both the file path:
And also, in the cache files themselves:
You can debug this by setting opcache.log_verbosity_level=4
.
On startup, if the file cache is enabled, you'll see a message with the PHP build ID: