Systemctl reload php-fpm.service

Hi,
For some PHP application troubleshooting , we need to find out the detail what operation/action happens when we reload the php-fpm daemon by systemd

exceuting the command

systemctl reload php-fpm.service

[ktahir]$ systemctl status php-fpm.service
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2024-08-14 07:25:21 +04; 3h 52min ago
  Process: 19394 ExecReload=/bin/kill -USR2 $MAINPID (code=exited, status=0/SUCCESS)

its configuration file is located at /usr/lib/systemd/system/php-fpm.service

From this file

# cat /usr/lib/systemd/system/php-fpm.service

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=notify
ExecStart=/usr/sbin/php-fpm --nodaemonize
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
RuntimeDirectory=php-fpm
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target


We can see that it is doing

ExecReload=/bin/kill -USR2 $MAINPID

Now how to find further details of this SIGUSR2 ?

According to man 7 signal:

Signal           Standard   Action   Comment
────────────────────────────────────────
SIGUSR2      P1990      Term     User-defined signal 2

So you should refer to the source code of php.
I think you can start with fpm_signals.c.

2 Likes

See

$ man php-fpm
...
              SIGINT,SIGTERM      immediate termination
              SIGQUIT             graceful stop
              SIGUSR1             re-open log file
              SIGUSR2             graceful reload of all workers + reload of fpm conf/binary
...
3 Likes

PID of the work process are changing with reloading.

Is this β€œgraceful reload of all workers” killing all the current wokers and creating new processes?

In this case it will cause the interuption to user whose request is in progress . right ?

]# ps -elf | grep php-fpm
4 S root         857       1  0  80   0 - 13930 ep_pol 07:25 ?        00:00:01 php-fpm: master process (/etc/php-fpm.conf)
5 S apache     20555     857  0  80   0 - 13949 skb_wa 13:29 ?        00:00:00 php-fpm: pool www
5 S apache     20556     857  0  80   0 - 13949 skb_wa 13:29 ?        00:00:00 php-fpm: pool www
5 S apache     20557     857  0  80   0 - 13949 skb_wa 13:29 ?        00:00:00 php-fpm: pool www
5 S apache     20558     857  0  80   0 - 13949 skb_wa 13:29 ?        00:00:00 php-fpm: pool www
5 S apache     20559     857  0  80   0 - 13949 skb_wa 13:29 ?        00:00:00 php-fpm: pool www
5 S apache     20560     857  0  80   0 - 13949 skb_wa 13:29 ?        00:00:00 php-fpm: pool www
5 S apache     20561     857  0  80   0 - 13949 skb_wa 13:29 ?        00:00:00 php-fpm: pool www
5 S apache     20562     857  0  80   0 - 13949 skb_wa 13:29 ?        00:00:00 php-fpm: pool www
5 S apache     20563     857  0  80   0 - 13949 skb_wa 13:29 ?        00:00:00 php-fpm: pool www
5 S apache     20564     857  0  80   0 - 13949 skb_wa 13:29 ?        00:00:00 php-fpm: pool www
0 S root       20710   20401  0  80   0 -  3381 pipe_w 13:34 pts/0    00:00:00 grep --color=auto php-fpm

# systemctl reload php-fpm.service

# ps -elf | grep php-fpm
4 S root         857       1  0  80   0 - 13930 ep_pol 07:25 ?        00:00:01 php-fpm: master process (/etc/php-fpm.conf)
5 S apache     20732     857  0  80   0 - 13949 skb_wa 13:34 ?        00:00:00 php-fpm: pool www
5 S apache     20733     857  0  80   0 - 13949 skb_wa 13:34 ?        00:00:00 php-fpm: pool www
5 S apache     20734     857  0  80   0 - 13949 skb_wa 13:34 ?        00:00:00 php-fpm: pool www
5 S apache     20735     857  0  80   0 - 13949 skb_wa 13:34 ?        00:00:00 php-fpm: pool www
5 S apache     20736     857  0  80   0 - 13949 skb_wa 13:34 ?        00:00:00 php-fpm: pool www
5 S apache     20737     857  0  80   0 - 13949 skb_wa 13:34 ?        00:00:00 php-fpm: pool www
5 S apache     20738     857  0  80   0 - 13949 skb_wa 13:34 ?        00:00:00 php-fpm: pool www
5 S apache     20739     857  0  80   0 - 13949 skb_wa 13:34 ?        00:00:00 php-fpm: pool www
5 S apache     20740     857  0  80   0 - 13949 skb_wa 13:34 ?        00:00:00 php-fpm: pool www
5 S apache     20741     857  0  80   0 - 13949 skb_wa 13:34 ?        00:00:00 php-fpm: pool www
0 S root       20749   20401  0  80   0 -  3381 pipe_w 13:34 pts/0    00:00:00 grep --color=auto php-fpm


I think it will wait for a while, but it could be very confusing if you reload php-fpm without taking the web server into account. I stop apache first, then stop php-fpm, then start in reverse order. Application design makes a difference; php makes sense for requests that run quickly and then finish, but some applications have long running php scripts that can cause all kinds of problems, e.g. phpmyadmin has a script to import a database that can run for ages.

Graceful reload means that the workers stop to accept new connections and finish their running tasks. Behind the scenes SIGQUIT is being sent to the workers.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.