佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > php7中停止php-fpm服務的方法詳解

php7中停止php-fpm服務的方法詳解

熱門標簽:Linux服務器 Mysql連接數(shù)設置 銀行業(yè)務 服務器配置 阿里云 科大訊飛語音識別系統(tǒng) 團購網(wǎng)站 電子圍欄

在PHP生命周期的各個階段,一些與服務相關的操作都是通過SAPI接口實現(xiàn)。

各個服務器抽象層之間遵守著相同的約定,這里我們稱之為SAPI接口。

在PHP的源碼中,當需要調用服務器相關信息時,全部通過SAPI接口中對應的方法調用實現(xiàn)

php-fpm + nginx
php + terminal
... 

PHP常見的四種運行模式

SAPI(Server Application Programming Interface)服務器應用程序編程接口,即PHP與其他應用交互的接口.
每個SAPI實現(xiàn)都是一個_sapi_module_struct結構體變量。

PHP腳本要執(zhí)行有很多方式,通過Web服務器,或者直接在命令行下,也可以嵌入在其他程序中。

SAPI提供了一個和外部通信的接口,常見的SAPI有:cgi、fast-cgi、cli、isapi apache模塊的DLL

  1. ISAPI模式 (eg Apache : apache2handler mode ) 以web服務器的一個模塊加載運行,其實就是將PHP的源碼與webServer的代碼一起編譯,運行時是同一個進程,共享同一個地址空間. 例如 LAMP中,PHP就是作為Apache的一個模塊運行的.Apache是多線程調用php模塊的.(same as IIS)
  2. CGI模式 fork-and-execute webServer將動態(tài)請求轉發(fā)到CGI程序(以php為例子),就相當于fork一個子進程,然后exec(php process),用CGI程序來解釋請求內容,最后將子進程的output返回.此時webServer與php進程的地址空間是獨立的.此時的php是作為一個獨立的程序運行.
  3. FastCGI模式 這種形式是CGI的加強版本,CGI是單進程,多線程的運行方式,程序執(zhí)行完成之后就會銷毀,所以每次都需要加載配置和環(huán)境變量(創(chuàng)建-執(zhí)行)。
    而FastCGI則不同,F(xiàn)astCGI 是一個常駐 (long-live) 型的 CGI,它可以一直執(zhí)行著,只要激活后,不會每次都要花費時間去 fork 一次。
  4. CLI command line interface

CLI

php_module_startup
php_request_startup
php_execute_script
php_request_shutdown
php_module_shutdown

PHP-FPM

php 5.3.3 以后的php-fpm不再支持php-fpm (start|stop|reload)等命令,需要使用信號控制.php-fpm master進程可以理解以下信號

  • kill -USR1 "php-fpm master pid" 重新打開日志文件. 執(zhí)行完畢后 你會發(fā)現(xiàn)php-fpm master/worker進程id not change
  • kill -USR2 "php-fpm master pid" 平滑重載所有php-fpm進程,執(zhí)行完畢后你會發(fā)現(xiàn)php-fpm master/worker進程id have changed.
  • kill -KILL/-9 php-fpm-master.pid , 強制殺死m(xù)aster進程,該信號不允許中斷/阻塞,此時master進程無法通知回收worker進程,所以此時worker進程仍然監(jiān)聽port,仍然可以正常處理http請求.
  • kill -INT/-QUIT/-TERM master pid , stop php-fpm service 信號被當前進程樹接收到.也就是說,不僅當前進程會收到信號,它的子進程也會收到.
  • kill master pid 發(fā)送SIGTERM信號到進程 信號可能會被阻塞,master可以回收worker進程.

example.

[sujianhui@dev529 ~]$>ps aux | grep php-fpm
root     17000  0.0  0.0 243220  7208 ?        Ss   17:00   0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
sujianh+ 17001  0.0  0.0 245304  7072 ?        S    17:00   0:00 php-fpm: pool www
sujianh+ 17002  0.0  0.0 245304  7072 ?        S    17:00   0:00 php-fpm: pool www
sujianh+ 17069  0.0  0.0 112816   976 pts/3    S+   17:01   0:00 grep --color=auto php-fpm

[sujianhui@dev529 ~]$>sudo kill -USR1 17000
[sujianhui@dev529 ~]$>ps aux | grep php-fpm
root     17000  0.0  0.0 243220  7208 ?        Ss   17:00   0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
sujianh+ 17001  0.0  0.0 245304  7072 ?        S    17:00   0:00 php-fpm: pool www
sujianh+ 17002  0.0  0.0 245304  7072 ?        S    17:00   0:00 php-fpm: pool www
sujianh+ 17105  0.0  0.0 112816   972 pts/3    S+   17:01   0:00 grep --color=auto php-fpm


[sujianhui@dev529 ~]$>sudo kill -USR2 17000
[sujianhui@dev529 ~]$>ps aux | grep php-fpm
root     17122  0.0  0.0 243220  7212 ?        Ss   17:01   0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
sujianh+ 17123  0.0  0.0 245304  7072 ?        S    17:01   0:00 php-fpm: pool www
sujianh+ 17124  0.0  0.0 245304  7072 ?        S    17:01   0:00 php-fpm: pool www
sujianh+ 17126  0.0  0.0 112816   976 pts/3    S+   17:01   0:00 grep --color=auto php-fpm

[sujianhui@dev529 ~]$>pstree 17122 -a
php-fpm
  ├─php-fpm          
  └─php-fpm          
[sujianhui@dev529 ~]$>sudo kill -INT 17122
[sujianhui@dev529 ~]$>ps aux | grep php-fpm
sujianh+ 17229  0.0  0.0 112816   976 pts/3    S+   17:03   0:00 grep --color=auto php-fpm

so we should use sudo kill -INT master.pid to kill php-fpm service.

nginx的master-worker機制與fpm大體相同.但是有一個問題需要注意,使用systemctl啟動起來的master被kill以后,worker也會死掉.

正常啟動nginx,kill掉master

[sujianhui@dev0529 sbin]$>which nginx
/usr/sbin/nginx
[sujianhui@dev0529 sbin]$>sudo nginx 
[sujianhui@dev0529 sbin]$>ps aux | grep nginx
root      4562  0.0  0.0  46608  1084 ?        Ss   21:46   0:00 nginx: master process nginx
sujianh+  4563  0.0  0.0  49128  2088 ?        S    21:46   0:00 nginx: worker process
sujianh+  4578  0.0  0.0 112812   972 pts/0    S+   21:46   0:00 grep --color=auto nginx

[sujianhui@dev0529 sbin]$>sudo kill -9 4562
[sujianhui@dev0529 sbin]$>ps aux | grep nginx
sujianh+  4563  0.0  0.0  49128  2088 ?        S    21:46   0:00 nginx: worker process
sujianh+  4612  0.0  0.0 112812   972 pts/0    S+   21:46   0:00 grep --color=auto nginx
[sujianhui@dev0529 sbin]$>kill -9 4563
[sujianhui@dev0529 sbin]$>ps aux | grep nginx
sujianh+  4638  0.0  0.0 112812   972 pts/0    S+   21:47   0:00 grep --color=auto nginx

使用systemctl啟動的master被kill掉以后,worker也會殺掉

[sujianhui@dev0529 sbin]$>systemctl start nginx
[sujianhui@dev0529 sbin]$>ps aux | grep nginx
root      4678  0.0  0.0  46608  1072 ?        Ss   21:47   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
sujianh+  4679  0.0  0.0  49124  2080 ?        S    21:47   0:00 nginx: worker process
sujianh+  4702  0.0  0.0 112812   972 pts/0    S+   21:47   0:00 grep --color=auto nginx
[sujianhui@dev0529 sbin]$>sudo kill -9 4678
[sujianhui@dev0529 sbin]$>ps aux | grep nginx
sujianh+  4732  0.0  0.0 112812   972 pts/0    S+   21:47   0:00 grep --color=auto nginx

rective run

[sujianhui@dev529 ~]$>kill -l
 1) SIGHUP	 2) SIGINT	 3) SIGQUIT	 4) SIGILL	 5) SIGTRAP
 6) SIGABRT	 7) SIGBUS	 8) SIGFPE	 9) SIGKILL	10) SIGUSR1
11) SIGSEGV	12) SIGUSR2	13) SIGPIPE	14) SIGALRM	15) SIGTERM
16) SIGSTKFLT	17) SIGCHLD	18) SIGCONT	19) SIGSTOP	20) SIGTSTP
21) SIGTTIN	22) SIGTTOU	23) SIGURG	24) SIGXCPU	25) SIGXFSZ
26) SIGVTALRM	27) SIGPROF	28) SIGWINCH	29) SIGIO	30) SIGPWR
31) SIGSYS	34) SIGRTMIN	35) SIGRTMIN+1	36) SIGRTMIN+2	37) SIGRTMIN+3
38) SIGRTMIN+4	39) SIGRTMIN+5	40) SIGRTMIN+6	41) SIGRTMIN+7	42) SIGRTMIN+8
43) SIGRTMIN+9	44) SIGRTMIN+10	45) SIGRTMIN+11	46) SIGRTMIN+12	47) SIGRTMIN+13
48) SIGRTMIN+14	49) SIGRTMIN+15	50) SIGRTMAX-14	51) SIGRTMAX-13	52) SIGRTMAX-12
53) SIGRTMAX-11	54) SIGRTMAX-10	55) SIGRTMAX-9	56) SIGRTMAX-8	57) SIGRTMAX-7
58) SIGRTMAX-6	59) SIGRTMAX-5	60) SIGRTMAX-4	61) SIGRTMAX-3	62) SIGRTMAX-2
63) SIGRTMAX-1	64) SIGRTMAX	

[sujianhui@dev529 ~]$>sudo nginx 
[sudo] password for sujianhui: 
[sujianhui@dev529 ~]$>ps aux | grep nginx
root      3628  0.0  0.0  46600  1052 ?        Ss   09:49   0:00 nginx: master process nginx
sujianh+  3629  0.0  0.0  49096  2056 ?        S    09:49   0:00 nginx: worker process
sujianh+  3637  0.0  0.0 112812   972 pts/0    S+   09:49   0:00 grep --color=auto nginx

[sujianhui@dev529 ~]$>sudo kill -SIGTERM 3628
[sujianhui@dev529 ~]$>ps aux | grep nginx
sujianh+  3744  0.0  0.0 112812   972 pts/0    S+   09:50   0:00 grep --color=auto nginx

[sujianhui@dev529 ~]$>sudo nginx 
[sujianhui@dev529 ~]$>ps aux | grep nginx
root      3766  0.0  0.0  46600  1052 ?        Ss   09:51   0:00 nginx: master process nginx
sujianh+  3767  0.0  0.0  49096  2056 ?        S    09:51   0:00 nginx: worker process
sujianh+  3775  0.0  0.0 112812   972 pts/0    S+   09:51   0:00 grep --color=auto nginx
[sujianhui@dev529 ~]$>sudo kill -9 3766
[sujianhui@dev529 ~]$>ps aux | grep nginx
sujianh+  3767  0.0  0.0  49096  2056 ?        S    09:51   0:00 nginx: worker process
sujianh+  3799  0.0  0.0 112812   972 pts/0    S+   09:51   0:00 grep --color=auto nginx

apache prefork

總結

到此這篇關于php7中停止php-fpm服務的文章就介紹到這了,更多相關php7停止php-fpm服務內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • PHP與以太坊交互詳解
  • php實現(xiàn)單筆轉賬到支付寶功能
  • php實現(xiàn)微信企業(yè)轉賬功能
  • 微信企業(yè)轉賬之入口類分裝php代碼
  • php實現(xiàn)微信公眾號企業(yè)轉賬功能
  • PHP 對接美團大眾點評團購券(門票)的開發(fā)步驟
  • PHP小程序后臺部署運行 LNMP+WNMP的方法
  • 為PHP模塊添加SQL SERVER2012數(shù)據(jù)庫的步驟詳解
  • php微信小程序解包過程實例詳解
  • 利用ajax+php實現(xiàn)商品價格計算
  • PHP實現(xiàn)創(chuàng)建以太坊錢包轉賬等功能

標簽:棗莊 廣元 萍鄉(xiāng) 蚌埠 衢州 江蘇 衡水 大理

巨人網(wǎng)絡通訊聲明:本文標題《php7中停止php-fpm服務的方法詳解》,本文關鍵詞  ;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    德令哈市| 苗栗市| 洛隆县| 南汇区| 锡林郭勒盟| 惠州市| 横峰县| 嘉善县| 池州市| 左云县| 三亚市| 苏尼特左旗| 米林县| 丽水市| 潼关县| 额济纳旗| 扶风县| 凤山市| 高平市| 富阳市| 高要市| 会理县| 博乐市| 同仁县| 定结县| 华亭县| 大竹县| 高陵县| 通许县| 东台市| 黔东| 璧山县| 嘉荫县| 白玉县| 亳州市| 城口县| 潞城市| 武冈市| 雅安市| 永登县| 报价|