I’m asking for help with what I think is a non-trivial question that I’ve been trying to solve for a few weeks now.
I recently upgraded my project to Symfony 5.4. However, after deploying the project to a Kubernetes cluster, php-fpm stopped working in pods. I wrote more about this process here. I was immediately sent to look at logs, conifigs and so on, but I made sure that there was no problem with that. And here’s why:
The fact is that in order to reproduce the problem, ALWAYS(!) two conditions are needed:
- Symfony 5.4 packages
- A remote Kubernetes cluster.
In all other cases, the problem does NOT(!) reproduce.
This means that if I, while in a Kubernetes cluster, rollback packages to version 4.4 and everything works fine. On the other hand, on my local machine where there is no Kubernetes cluster, after updating the project to version 5.4, php-fpm also works fine. Both configs are the same, php-fpm versions are the same. Everything is literally identical. From this I conclude that the remote configs are configured correctly and there is no fundamental incompatibility of Symfony packages with the installed fpm.
I thought that maybe not enough resources to start/update the system, but:
- Composer updated the project during the build stage, but the problem occurs during the deployment stage.
- I don’t think the Kubernetes cluster is so loaded that it can’t handle the simple task that my laptop can handle.
- There are no signals from Kubernetes that there is not enough memory or anything else. The cluster just ignores running php-fpm without a single message.
So, what can be the problem?
UPD:
I can watch the pod logs and I can see how my entrypoint
file is executed, by this:
-
After performing all migrations, the log file shows the entry
[OK] Already at the latest version ("AppMigrationsVersion20230427064413")
. From this I conclude that the migrations worked successfully and didn’t break my application. -
Cache warming up is successful, as evidenced by the line in the logs
[OK] Cache for the "prod" environment (debug=false) was successfully warmed.
-
In the entrypoint given here I really don’t use the
$ php-fpm --test
command, however, I can assure you that I have run the command with the-t
flag and--debug
flag before and there were no errors. The logs showNOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful
. -
This is my problem, yes.
-
My Symfony 4.4 project runs on the same base image
php:8.0-fpm-alpine3.16
in exactly the same Kubernetes pod configuration, from which I conclude that OPcache is compatible with PHP version 8.0. However, to be even more sure, I commented out the lines;opcache.preload=/var/www/app/var/cache/prod/srcCimple_KernelProdContainer.preload.php ;opcache.preload_user=www-data
in myphp.ini
and the problem did not go away
UPD 2
-
I tried to print out the code that the
php-fpm -F
command returns. The output is0
, which indicates successful completion of the command, with no errors. -
That’s what I tried to do, I first separately update the recipes, prepare the code and make sure that at each step the project runs. The problem is that the project runs locally even with a fully updated Symfony. The problem with php-fpm happens as soon as I update
composer update "symfony/*"
from 4.4 to 5.1 or higher. Or should I try to update packages one by one ? Is it possible ? -
I left only one line in
index.php
–require dirname(__DIR__).'/vendor/autoload.php;
and the problem is still there.
I was able to find out some more information about this bug: there are lines in the entrypoint
file
php-fpm -F &
nginx -g 'daemon off;' &
So, I commented out the line with nginx
and found out that php-fpm
works correctly in this case. Hence, no problem with PHP FPM as such, the problem is that the command nginx -g 'daemon off;' &
somehow blocks my fpm. Could it be related to the new rules for nginx config in Symfony 5.4 ?
I have created a new question.
2
Answers
The problem was that
OPcache
was configured incorrectly.However, you should be careful when checking. When I was told to turn off the
JIT (OPcache)
, I just commented out the settings inphp.ini
:But this is not enough. I also had to rebuild the project.
You run
app:migrations:migrate
which can fail the script (should be done in initContainer).You run
cache:warmup
which can fail the script.You do not run
$ php-fpm --test
, to verify that you config actually valid.You update
symfony
, which may contain bugs, which appears only on cloud hardware.You using JIT (OPcache) and it just not work (8.0, 8.1 problem). You can try disable opcache extension.
Try to connect to the pod and run project through builtin php server, not php-fpm, if it still not runs, then try to change php version.