说明:
从php5.3.*开始,源码中开始包含 php-fpm,不用专门再打补丁了,只需要解开源码直接configure。php-fpm 不再支持php 5.2 php-fpm 补丁具有的 /usr/local/php/sbin/php-fpm (start|stop|reload)等命令,因此需要使用信号控制php-fpm的启动,关闭等。
php-fpm master进程可以理解以下信号
SIGINT, SIGTERM 立刻终止
SIGQUIT 平滑终止
SIGUSR1 重新打开日志文件
SIGUSR2 平滑重载所有worker进程并重新载入配置和二进制模块
实现:
编写php-fpm,添加如下内容
vim /etc/init.d/php-fpm
#!/bin/sh function_start_php_fpm() { printf "Starting php-fpm...n" /usr/local/webserver/php/sbin/php-fpm } function_stop_php_fpm() { printf "Stoping php-fpm...n" # kill -SIGINT `cat /usr/local/php/var/run/php-fpm.pid` /bin/kill -SIGQUIT `cat /usr/local/webserver/php/var/run/php-fpm.pid` } function_reload_php_fpm() { printf "Reloading php-fpm...n" /bin/kill -SIGUSR2 `cat /usr/local/webserver/php/var/run/php-fpm.pid` } function_restart_php_fpm() { printf "Restarting php-fpm...n" function_stop_php_fpm sleep 5 function_start_php_fpm } if [ "$1" = "start" ]; then function_start_php_fpm elif [ "$1" = "stop" ]; then function_stop_php_fpm elif [ "$1" = "reload" ]; then function_reload_php_fpm elif [ "$1" = "restart" ]; then function_restart_php_fpm else printf "Usage: /usr/local/sbin/php-fpm {start|stop|reload|restart}n" fi
这样就可以通过/etc/init.d/php-fpm start|stop|reload|restart 实现php-fpm关闭,重启了