Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to use php 7.4 preloading #409

Open
rbaarsma opened this issue May 17, 2020 · 12 comments
Open

ability to use php 7.4 preloading #409

rbaarsma opened this issue May 17, 2020 · 12 comments
Assignees

Comments

@rbaarsma
Copy link

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 :)

@dzuelke dzuelke self-assigned this Jul 9, 2020
@holtkamp
Copy link

holtkamp commented Aug 24, 2020

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: php/doc-en@83c41a8

@bjornpost
Copy link

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/

@holtkamp
Copy link

@bjornpost thanks for the insight, did you observe any (significant) improvements?

@bjornpost
Copy link

bjornpost commented Aug 25, 2020

@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.

@holtkamp
Copy link

@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

@bjornpost
Copy link

@holtkamp did you manage to get it working?

@holtkamp
Copy link

holtkamp commented Oct 6, 2020

Did not try yet... Hopefully "this year"...

@jwage
Copy link

jwage commented Dec 19, 2020

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?

@nileio
Copy link

nileio commented Aug 16, 2021

@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

@jwage
Copy link

jwage commented Jul 6, 2022

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?

@dzuelke
Copy link
Contributor

dzuelke commented Jul 12, 2022

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?

@nicholasruunu
Copy link

nicholasruunu commented May 10, 2023

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants