When managing PHP-FPM services, you might encounter this puzzling scenario:
$ service php5-fpm start
php5-fpm start/running, process 4516
$ service php5-fpm status
php5-fpm stop/waiting
$ ps aux | grep php
www-data 3552 0.0 0.7 338108 14960 ? S 05:43 0:00 php-fpm: pool www
www-data 3553 0.0 1.3 338168 27156 ? S 05:43 0:00 php-fpm: pool www
The service appears to start successfully, yet status checks report "stop/waiting" while worker processes continue running. This indicates the master process may have terminated unexpectedly while leaving child processes orphaned.
Several factors could contribute to this behavior:
- Init script miscommunication: The init script fails to properly track the master process PID
- FastCGI process manager crash: The master process exits but workers remain
- PID file issues: Stale or incorrectly located PID files
- Upstart/SysV conflicts: Common on Ubuntu systems with both init systems
First, verify the actual process hierarchy:
$ pstree -p | grep php
|-php-fpm(1234)-+-php-fpm(2345)
|-php-fpm(2346)
-php-fpm(2347)
$ sudo netstat -tulpn | grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1234/php-fpm: maste
Check PID file location and contents:
$ cat /var/run/php5-fpm.pid
1234
$ ps -p 1234
PID TTY TIME CMD
1234 ? 00:00:01 php-fpm: master
For Ubuntu 14.04 systems, try these solutions:
# Clean up any existing processes
$ sudo killall php-fpm
# Reset the init script
$ sudo update-rc.d php5-fpm defaults
$ sudo update-rc.d php5-fpm enable
# Alternative restart sequence
$ sudo service php5-fpm stop
$ sudo rm -f /var/run/php5-fpm.pid
$ sudo service php5-fpm start
Modify /etc/php5/fpm/php-fpm.conf
:
; Ensure proper PID file handling
pid = /var/run/php5-fpm.pid
; Add emergency restart settings
emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 10s
If upgraded to systemd:
$ sudo systemctl daemon-reload
$ sudo systemctl restart php5-fpm.service
$ sudo systemctl status php5-fpm.service
Create a watchdog script /usr/local/bin/php-fpm-monitor
:
#!/bin/bash
MASTER_PID=$(cat /var/run/php5-fpm.pid 2>/dev/null)
if [ -z "$MASTER_PID" ] || ! ps -p $MASTER_PID > /dev/null; then
echo "Master process not running - restarting"
service php5-fpm restart
fi
exit 0
Add to cron:
*/5 * * * * root /usr/local/bin/php-fpm-monitor
html
When running service php5-fpm status
after a restart, you might encounter contradictory output where the service reports stop/waiting
while PHP pages continue to load normally. Process inspection reveals active worker processes:
ps -aux | grep php
www-data 3552 0.0 0.7 338108 14960 ? S 05:43 0:00 php-fpm: pool www
www-data 3553 0.0 1.3 338168 27156 ? S 05:43 0:00 php-fpm: pool www
The core issue typically stems from the init system (Upstart in Ubuntu 14.04) losing track of the master process PID. Check for the master process explicitly:
ps -ef | grep php-fpm | grep master
root 4516 1 0 05:43 ? 00:00:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
If this command returns empty, your master process has detached from the init system's control.
Examine these critical settings in /etc/php5/fpm/php-fpm.conf
:
; Process manager settings
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pm.process_idle_timeout = 10s
Ubuntu 14.04's Upstart script (/etc/init/php5-fpm.conf
) may need modification. Add these stanzas:
respawn
respawn limit unlimited
expect daemon
Create a systemd service override (for Ubuntu 16.04+) or modify Upstart behavior:
# For systemd systems
sudo systemctl edit php7.4-fpm
[Service]
PIDFile=/run/php/php7.4-fpm.pid
Restart=always
Enable verbose logging temporarily:
; /etc/php5/fpm/php-fpm.conf
log_level = debug
Then monitor logs in real-time:
tail -f /var/log/php5-fpm.log
For critical systems, consider process supervision:
# Using supervisor
[program:php-fpm]
command=/usr/sbin/php-fpm --nodaemonize
autostart=true
autorestart=true