0

I'm trying to configure a php-fpm server with Debian9 and SystemD as good as I can, but I have found a problem that drives me crazy. I have searched and researched all as I can, and nothing, I have no any positive result.

I'm monitoring php-fpm with:

watch -n.1 "systemctl status php72"

The main problem

When I try to call

kill -USR2 php-fpm-pid

it waits till process_control_timeout passes (in my case 60seconds), then kills all the childrens at once (sends the SIGTERM to the childrens). It seems that SIGQUIT is doing nothing nor arribing to the child processes.

If I try to call

systemctl kill -s USR2 php72.service

it kills all the processes at moment and generates error 500 on apache.

The context where it all happens

debug log

[26-Mar-2019 12:24:17.890902] DEBUG: pid 1837, fpm_got_signal(), line 111: received SIGUSR2
[26-Mar-2019 12:24:17.891061] NOTICE: pid 1837, fpm_got_signal(), line 112: Reloading in progress ...
[26-Mar-2019 12:24:17.891085] DEBUG: pid 1837, fpm_pctl(), line 230: switching to 'reloading' state
[26-Mar-2019 12:24:17.891225] DEBUG: pid 1837, fpm_pctl_kill_all(), line 158: [pool www72] sending signal 3 SIGQUIT to child 1839
[26-Mar-2019 12:24:17.891248] DEBUG: pid 1837, fpm_pctl_kill_all(), line 158: [pool temp-site.io] sending signal 3 SIGQUIT to child 1840
[26-Mar-2019 12:24:17.891370] DEBUG: pid 1837, fpm_pctl_kill_all(), line 167: 2 child(ren) still alive
[26-Mar-2019 12:24:17.891393] DEBUG: pid 1837, fpm_event_loop(), line 418: event module triggered 1 events
[26-Mar-2019 12:25:01.905047] DEBUG: pid 1837, fpm_got_signal(), line 75: received SIGCHLD
[26-Mar-2019 12:25:01.905186] DEBUG: pid 1837, fpm_children_bury(), line 252: [pool temp-site.io] child 1840 exited with code 0 after 52.621960 seconds from start
[26-Mar-2019 12:25:01.905231] DEBUG: pid 1837, fpm_event_loop(), line 418: event module triggered 1 events
[26-Mar-2019 12:25:17.892532] DEBUG: pid 1837, fpm_pctl_kill_all(), line 158: [pool www72] sending signal 15 SIGTERM to child 1839
[26-Mar-2019 12:25:17.892561] DEBUG: pid 1837, fpm_pctl_kill_all(), line 167: 1 child(ren) still alive
[26-Mar-2019 12:25:17.894222] DEBUG: pid 1837, fpm_got_signal(), line 75: received SIGCHLD
[26-Mar-2019 12:25:17.894264] DEBUG: pid 1837, fpm_children_bury(), line 252: [pool www72] child 1839 exited on signal 15 (SIGTERM) after 68.611847 seconds from start
[26-Mar-2019 12:25:17.894273] NOTICE: pid 1837, fpm_pctl_exec(), line 97: reloading: execvp("/path/to/php72/sbin/php-fpm", {"/path/to/php72/sbin/php-fpm", "--fpm-config", "/opt/php5-fpm/php72.conf", "--pid", "/var/run/php5/php72/php72.pid", "-F"})
[26-Mar-2019 12:25:18.296768] DEBUG: pid 1837, fpm_scoreboard_init_main(), line 39: got clock tick '100'
[26-Mar-2019 12:25:18.296832] NOTICE: pid 1837, fpm_sockets_init_main(), line 418: using inherited socket fd=8, "127.0.0.1:9720"
[26-Mar-2019 12:25:18.296839] NOTICE: pid 1837, fpm_sockets_init_main(), line 418: using inherited socket fd=9, "127.0.0.1:30739"
[26-Mar-2019 12:25:18.296852] DEBUG: pid 1837, fpm_socket_af_inet_socket_by_addr(), line 291: Found address for 127.0.0.1, socket opened on 127.0.0.1
[26-Mar-2019 12:25:18.296865] DEBUG: pid 1837, fpm_socket_af_inet_socket_by_addr(), line 291: Found address for 127.0.0.1, socket opened on 127.0.0.1
[26-Mar-2019 12:25:18.296876] DEBUG: pid 1837, fpm_event_init_main(), line 336: event module is epoll and 1 fds have been reserved
[26-Mar-2019 12:25:18.296904] NOTICE: pid 1837, fpm_init(), line 84: fpm is running, pid 1837
[26-Mar-2019 12:25:18.297702] DEBUG: pid 1837, fpm_children_make(), line 421: [pool www72] child 2086 started
[26-Mar-2019 12:25:18.298357] DEBUG: pid 1837, fpm_children_make(), line 421: [pool temp-site.io] child 2087 started
[26-Mar-2019 12:25:18.298414] DEBUG: pid 1837, fpm_pctl_heartbeat(), line 459: heartbeat have been set up with a timeout of 1666ms
[26-Mar-2019 12:25:18.298420] DEBUG: pid 1837, fpm_event_loop(), line 365: 258960 bytes have been reserved in SHM
[26-Mar-2019 12:25:18.298423] NOTICE: pid 1837, fpm_event_loop(), line 366: ready to handle connections

uname -a

Linux HOST 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 GNU/Linux

php-fpm.conf

[global]
process_control_timeout = 60s
error_log = /var/log/fpm-php.log
log_level = debug

[www72]
user = www-data
group = www-data
listen = 127.0.0.1:9720
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
pm = dynamic
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1
pm.max_children = 200
pm.process_idle_timeout = 10s
pm.max_requests = 10000

php_admin_value[open_basedir] = "/usr/local/home/domain.com/web"

; All sites .conf
include=/opt/php-fpm/*.conf

slowlog = /var/log/php_slow.log
request_slowlog_timeout = 5s

/opt/php-fpm/time-site.io.conf

[temp-site.io]
user = tempsite
group = tempsite
listen = 127.0.0.1:30739
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

pm = dynamic
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1
pm.max_children = 20
pm.process_idle_timeout = 10s
pm.max_requests = 10000

php flags to compile:

--without-apache \
--with-config-file-scan-dir \
--enable-fpm \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-xpm-dir \
--with-vpx-dir \
--with-freetype-dir \
--with-t1lib \
--enable-gd-native-ttf \
--with-openssl \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-intl \
--with-bz2 \
--with-curl \
--enable-dba=shared \
--with-imap \
--with-imap-ssl \
--with-kerberos \
--with-mcrypt \
--with-mssql \
--with-unixODBC=/usr \
--with-pdo-odbc=unixODBC,/usr \
--with-pdo-dblib \
--with-pdo-pgsql \
--with-pgsql \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-xmlrpc \
--with-xsl \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-ftp \
--enable-mbstring \
--enable-soap \
--enable-sockets \
--enable-wddx \
--enable-zip \
--with-zlib \
--with-gettext \
--enable-opcache

systemctl cat php72.service

[Unit]
Description=FPM-PHP [PHP php72] TCP 9720

[Service]
ExecStartPre=-/bin/mkdir -p /var/run/php5/php72/
ExecStart=/path/to/php72/sbin/php-fpm --fpm-config /opt/php-fpm/php72.conf --pid /var/run/php5/php72/php72.pid -F
#ExecReload=/bin/kill -USR2 $MAINPID #I have tried this option on and off
PIDFile=/var/run/php5/php72/php72.pid
Restart=on-failure

[Install]
WantedBy=multi-user.target

Maybe is this a bug on PHP-FPM? or a misconfiguration that I have?

  • During the writing of this post, I have tried to configure the pm as ondemand, and it worked better (no process, no problem), also, I need to have it into dynamic.

What more can I check to see where it is failing? (any help is welcome)

  • You are describing the exact expected behaviour, not a bug. What did I miss? What is your expected outcome? – bjoster Mar 26 at 16:58
  • @bjoster the expected behaviour is to reload the configuration before reaching the timeout and gracefully restart all the childrens. I think, that what I have mentioned is that it is NOT doing this. A php-fpm child without any incoming connection nor any load waits till timeout without gracefully reloading itself (and being killed with SIGTERM). – Marc Palau Mar 27 at 7:07
  • The expected behaviour of kill -USR2 php-fpm-pid is forcibly killing of all children after process_control_timeout and starting new ones (with reloaded config). That's exactly what it is doing, reading your question? – bjoster Mar 27 at 12:12
  • 1st, thanks for your reply @bjoster (I'm very grateful). If I read the manpage for php-fpm it says: SIGUSR2: graceful reload of all workers + reload of fpm conf/binary. So, I have another contexts (Debian7) where it works as spected, it closes all the childs that are no in use, and when there is no one more alive, it reloads the configuration and start again all the childs. The problem is, with Debian9 and the current version of php I'm using, no child is closing gracefully, master just waits till the process_control_timeout ends and then obviously force the kill of the childs. – Marc Palau Mar 28 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.