With >= PHP 7.4, support for opcache preloading was added, a feature that improves the application start performance up to 60%.
Keep in mind that it's a very new feature that might not be bug-free.
Some frameworks like Symfony are already providing scripts for preloading the entire code base to improve the performance.
- Open the
php.iniof your PHP Version:
- Search for
opcache.preloadand adjust the values:
By default, all PHP Versions on CloudPanel have a default PHP-FPM Pool running as user clp and group clp.
If you are using a custom PHP-FPM Pool, change the opcache.preload_user.
- Restart PHP-FPM to apply the changes.
You may also want to stay up to date with the Symfony Performance recommendations.
Laravel 7 & 8
preload.php for Laravel 7 & 8 from our Github Repository.
preload.php for Magento 2 from our Github Repository.
Other PHP Apps
You can use the generic preload script and configure it to your needs.
In the bottom of the script, you can add paths to add and ignore.
To test if the opcache preloading is working as expected we can check the output of opcache_get_status().
- Create a file like
t.phpin your document root:
- Add the lines of php code:
- Restart the PHP-FPM service to clear and preload the opcode cache:
- Open the file in the browser. The output will look like this:
As expected, we see all classes and functions are preloaded into the opcache.