heroku-buildpack-php
heroku-buildpack-php copied to clipboard
ability to use php 7.4 preloading
I cannot find any information on using the new php 7.4 preloading feature with Heroku. Since we need to input a path, I'm not sure if I can do it manually
For example in Symfony this can normally be enabled with a simple one-liner in the php.ini: https://symfony.com/doc/current/performance.html#use-the-opcache-class-preloading
It's supposed to add about 75% performance. That's quite a lot, so I'd like to use it - and I'm probably not the only one :)
For what it's worth: documentation on this functionality: https://www.php.net/manual/en/opcache.preloading.php had been published by the end of July 2020: https://github.com/php/doc-en/commit/83c41a8f69bacceef42fb99b2188bb8b24b2fe58
For me (on dokku/herokuish), putting this in user.ini seems to work (at least, doesn't give errors during deploy):
opcache.preload=/app/var/cache/prod/App_KernelProdContainer.preload.php
opcache.memory_consumption=256
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0
Make sure that user.ini is mentioned in your Procfile:
web: $(composer config bin-dir)/heroku-php-nginx -C nginx.conf -F fpm_custom.conf -i user.ini public/
@bjornpost thanks for the insight, did you observe any (significant) improvements?
@holtkamp I'm not sure how and where to measure these improvements, so I wouldn't dare to burn my fingers on that. I'm not noticing big improvements in ttfb on individual requests though.
@bjornpost maybe you see a drop in response time on something like NewRelic or the Heroku metrics 🤓. Will try to get it working as well and hopefully report back
@holtkamp did you manage to get it working?
Did not try yet... Hopefully "this year"...
Is this something that should work out of the box or does heroku need to do something to support the usage of opcache.preload in a .user.ini file?
@bjornpost .user.ini should be automatically picked up by heroku/dokku - so do you need to specifically specify that in Procfile using -i for opcode preloading to work. did anyone enable opcode preloading and can share metrics or tests prior and after
After looking in to this, not all ini settings can be set in a .user.ini file or in a custom phpfpm.conf
See this here https://www.php.net/manual/en/configuration.file.per-user.php
Only INI settings with the modes PHP_INI_PERDIR and PHP_INI_USER will be recognized in .user.ini-style INI files.
And you can see on this page https://www.php.net/manual/en/ini.list.php that the setting opcache.preload is PHP_INI_SYSTEM so I believe this setting has to be set another way in heroku.
This does not work either:
Procfile
web: heroku-php-nginx -C nginx.conf -F phpfpm.conf public/
phpfpm.conf
php_value[opcache.preload]=/app/var/cache/prod/App_KernelProdContainer.preload.php
php_value[opcache.memory_consumption]=256
php_value[opcache.max_accelerated_files]=20000
php_value[opcache.validate_timestamps]=0
Is it is possible to set these settings in the php.ini that is used when php-fpm starts?
The answer to @jwage's question is... heroku-php-{apache2,nginx} -i custom.ini, but keep in mind that you're completely replacing the production INI config this way.
Anyway... what do y'all think about PHP_OPCACHE__PRELOAD or something like that as an env var?
Did anyone figure this out in a way that doesn't replace the production ini?
Edit: I've been running some experiments and come up with this:
.heroku/compile.sh
#!/usr/bin/env bash
set -e
set -o pipefail
cat .heroku/php/etc/php/php.ini - <<'EOT' > config/php.ini
opcache.preload=/app/config/preload.php
opcache.memory_consumption=256
opcache.max_accelerated_files=20000
EOT
exit 0
composer.json
{
"scripts": {
"compile": [
"@php bin/console cache:clear --env=prod --no-optional-warmers --no-debug"
".heroku/compile.sh"
]
}
Procfile
web: vendor/bin/heroku-php-apache2 -C .heroku/apache.conf -i config/php.ini public/