Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Problem with auto-generated preload.php file for prod environment #37152

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

Closed
Nidhognit opened this issue Jun 8, 2020 · 2 comments
Closed

Problem with auto-generated preload.php file for prod environment #37152

Nidhognit opened this issue Jun 8, 2020 · 2 comments

Comments

@Nidhognit
Copy link

Symfony version(s) affected: 5.0.*
php: 7.4.*

Description
If you enable in php.ini configuration preloading for prod environment,
opcache.preload=/app/var/cache/prod/App_Infrastructure_KernelProdContainer.preload.php opcache.preload_user=www-data
you will see the next error during composer update command:

Fatal error: Uncaught Error: Class 'Symfony\Component\Console\Terminal' not found in /app/vendor/symfony/console/Application.php:84
Stack trace:
#0 phar:///usr/local/bin/composer/src/Composer/Console/Application.php(101): Symfony\Component\Console\Application->__construct('Composer', '1.10.7')
#1 phar:///usr/local/bin/composer/bin/composer(60): Composer\Console\Application->__construct()
#2 /usr/local/bin/composer(24): require('phar:///usr/loc...')
#3 {main}
  thrown in /app/vendor/symfony/console/Application.php on line 84

This error not reproduced for other environments.
If you will add Class 'Symfony\Component\Console\Terminal' to ...preload.php file, you will see another error.
I guess something wrong with ...preload.php file.

How to reproduce
I created simple project that contain only symfony code, with instruction how to reproduce it https://github.com/Nidhognit/symfony-error-example
You need to have docker-compose for it.

Additional context
Probably, this is composer error, but it happen only with symfony preload file and only for prod environment

@nicolas-grekas
Copy link
Member

Hi, thanks for the nice reproducer.
The reason is that composer is not compatible with recent versions of symfony/console and when preloading is used, the Application.php that is loaded is too recent for it.

The solution is either to set opcache.enable_cli=0, or to enable preloading only for php-fpm.

TL;DR: preloading is useless and conflicts with using PHP on the CLI.

Nothing we can do about here, that's one of its requirements.

@nicolas-grekas
Copy link
Member

I'm proposing a fix in #37353

fabpot added a commit that referenced this issue Jun 19, 2020
This PR was merged into the 4.4 branch.

Discussion
----------

[DI] disable preload.php on the CLI

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #37152
| License       | MIT
| Doc PR        | -

See linked issue for a nasty side-effect of preloading on the CLI. Many hosting solutions do not provide a way to set different ini settings for CLI vs FPM. Let's skip preloading anything on the CLI.

Commits
-------

50ccf2f [DI] disable preload.php on the CLI
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

5 participants