PHP-FPM is a FastCGI manager that can provide PHP parsing services for web servers such as Nginx and Apache. PHP-FPM manages multiple worker processes through the master process, and each worker process is an independent PHP parser. In order to ensure the stable operation of the PHP-FPM process, process guarding is required.
The following are common methods for PHP-FPM process daemons:
1. Use Supervisor for process daemon. Supervisor is a process manager that can run PHP-FPM's master process and all worker processes as child processes, and automatically restarts when the process crashes. In operating systems such as CentOS, you can use yum to install Supervisor:
yum install supervisor
Then add PHP-FPM configuration in /etc/supervisord.conf, for example:
[program:php-fpm]
command=/usr/local/php/sbin/php-fpm --nodaemonize
autostart=true
autorestart=true
user=nginx
The above configuration file specifies parameters such as PHP-FPM commands, startup automatic restart, and running user.
2. Use systemd for process daemon. systemd is a system and service manager on Linux systems that can be used to manage PHP-FPM processes. In the systemd configuration file /usr/lib/systemd/system/php-fpm.service, you can specify parameters such as PHP-FPM commands, running users, and startup methods, for example:
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
The above configuration file specifies the PID file, command, restart command and other parameters of PHP-FPM.
3. Use other process daemon tools, such as monit, runit, etc.
In short, in order to ensure the stable operation of the PHP-FPM process, process guarding is required. Common process daemon methods include using tools such as Supervisor and systemd. These tools can automatically restart the PHP-FPM process, and monitor the running status of the process to ensure that the process does not die.