简体   繁体   English

PHP-FPM (7.4.2) 不会优雅地停止?

[英]PHP-FPM (7.4.2) doesn't stop gracefully?

During updating, we want to stop php-fpm and wait for all running scripts to be finished before we make any file changes.在更新期间,我们希望停止 php-fpm 并等待所有正在运行的脚本完成,然后再进行任何文件更改。

We found out that we needed to set process_control_timeout, so we placed "process_control_timeout = 36000s" in "/etc/php/7.4/fpm/pool.d/zz-00-overrides.ini" (and we restarted php-fpm).我们发现我们需要设置process_control_timeout,所以我们在“/etc/php/7.4/fpm/pool.d/zz-00-overrides.ini”中放置了“process_control_timeout = 36000s”(然后我们重新启动了php-fpm)。

Then we created a test script to test it out.然后我们创建了一个测试脚本来测试它。 Our test script creates a file, then 30 seconds later, it creates another file.我们的测试脚本创建一个文件,然后 30 秒后,它创建另一个文件。 The script:剧本:

$id = random_int(10000, 99999);
file_put_contents(__DIR__ . '/' . $id . '-start', '');
sleep(30);
file_put_contents(__DIR__ . '/' . $id . '-end', '');

When we run the script normally (browser -> nginx -> php-fpm), it creates the 1st file, 30 seconds later it creates the 2nd file.当我们正常运行脚本时(浏览器 -> nginx -> php-fpm),它创建第一个文件,30 秒后创建第二个文件。

When we run the script, wait a few seconds, and then try to stop it (run the same way as before: browser -> nginx -> php-fpm) (stopped by: "service php7.4-fpm stop"), it will create the 1st file, then the service stop command is run which only takes 2-3 seconds, then the browser says "502 Bad Gateway", and then the 2nd file is never created.当我们运行脚本时,等待几秒钟,然后尝试停止它(运行方式与之前相同:浏览器-> nginx -> php-fpm)(停止方式为:“service php7.4-fpm stop”),它将创建第一个文件,然后运行服务停止命令,只需要 2-3 秒,然后浏览器显示“502 Bad Gateway”,然后永远不会创建第二个文件。

It doesn't gracefully stop.它不会优雅地停止。 The desired outcome for us is that "service php7.4-fpm stop" waits for all the scripts to be done, and then stops, instead of it killing off any running scripts the way it is doing now in order to forcefully stop.我们期望的结果是“service php7.4-fpm stop”等待所有脚本完成,然后停止,而不是像现在这样杀死任何正在运行的脚本以强行停止。

Are we missing something, are we doing something wrong?我们是否遗漏了什么,我们做错了什么吗? Is it a bug somewhere somehow?它是某个地方的错误吗? Any help would be really appreciated.任何帮助将非常感激。

  • Debian 10 (Linux 4.19.0-6-cloud-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 GNU/Linux) Debian 10(Linux 4.19.0-6-cloud-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 GNU/Linux)
  • PHP 7.4.2 PHP 7.4.2
  • Nginx 1.14.2 nginx 1.14.2

Running kill -QUIT $(cat /run/php/php7.4-fpm.pid) does take the process_control_timeout config in account.运行kill -QUIT $(cat /run/php/php7.4-fpm.pid)确实考虑了process_control_timeout配置。 It will cause the PHP-FPM process to stop as soon as all the scripts have finished their execution.一旦所有脚本完成执行,它就会导致 PHP-FPM 进程停止。 At that point the PID will be removed.届时,PID 将被删除。 So, in order to make it work:因此,为了使其工作:

  1. run $(kill -QUIT $(cat /run/php/php7.4-fpm.pid))运行$(kill -QUIT $(cat /run/php/php7.4-fpm.pid))
  2. in a loop, check if /run/php/php7.4-fpm.pid still exists, if not, break the loop.在循环中,检查/run/php/php7.4-fpm.pid仍然存在,如果不存在,则中断循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM