搜尋
首頁後端開發PHP7FPM鮮為人知的三種模式

我們常使用php-fpm,但不一定所有人都知道fpm有三種模式,今天小年就帶大家了解一下fpm的三種模式,有需要的可以參考參考。

FPM鮮為人知的三種模式

; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
;   dynamic - the number of child processes are set dynamically based on the
;             following directives. With this process management, there will be
;             always at least 1 children.
;             pm.max_children      - the maximum number of children that can
;                                    be alive at the same time.
;             pm.start_servers     - the number of children created on startup.
;             pm.min_spare_servers - the minimum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is less than this
;                                    number then some children will be created.
;             pm.max_spare_servers - the maximum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is greater than this
;                                    number then some children will be killed.
;  ondemand - no children are created at startup. Children will be forked when
;             new requests will connect. The following parameter are used:
;             pm.max_children           - the maximum number of children that
;                                         can be alive at the same time.
;             pm.process_idle_timeout   - The number of seconds after which
;                                         an idle process will be killed.
; Note: This value is mandatory.

pm有三種模式:static、dynamic和ondemand

static

這種方式比較簡單,在啟動時master依照pm.max_children配置fork出對應數量的worker進程,即worker進程數是固定不變的。

dynamic

動態處理管理,首先在fpm啟動時依照pm.start_servers初始化一定數量的worker。

運行期間如果master發現空閒worker數低於pm.min_spare_servers配置數(表示請求比較多,worker處理不過來了)則會fork worker進程,但總的worker數不能超過pm.max_children。

如果master發現空閒worker數超過了pm.max_spare_servers(表示閒著的worker太多了)則會殺掉一些worker,避免佔用過多資源,master透過這4個值來控制worker數。

ondemand

這種方式一般很少用,在啟動時不分配worker進程,等到有請求了後再通知master進程fork worker進程,總的worker數不超過pm. max_children,處理完成後worker進程不會立即退出,當空閒時間超過pm.process_idle_timeout後再退出。

pm.max_children:靜態方式下開啟的php-fpm進程數量。

pm.start_servers:動態方式下的起始php-fpm行程數量。

pm.min_spare_servers:動態方式下的最小php-fpm進程數。

pm.max_spare_servers:動態方式下的最大php-fpm行程數。

FPM對訊號的處理

php-fpm reload

php-fpm stop

kill SIGUSR1 php-fpm 重新使用新的文件,完成日誌切割

kill SIGUSR2 php-fpm 重新啟動work進程,重新載入設定檔

Q1:啟動php-fpm進程之後,kill php-fpm master進程號,還能繼續服務嗎? A: 不能(所有php-fpm進程都關閉)

Q2:啟動php-fpm進程之後,kill -9 php-fpm master進程號,還能繼續服務嗎? A: 能(只kill了 master進程,work進程還在工作)

Q2:啟動php-fpm進程之後,kill php-fpm work進程號,還能繼續服務嗎? A: 能(work行程被kill後,又新起一個work行程)

FPM的生命週期

php_module_startup()

##fcgi_accept_request()

php_request_startup()

fmp_request_executing()php_execute_script ()

fpm_requset_end()

#######php_request_shutdown()########因為fpm是常駐進程,所以在###php_request_shutdown()###之後又會從###fcgi_accept_request()###開始迴圈。 #########推薦學習:###php影片教學#######

以上是FPM鮮為人知的三種模式的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:CSDN。如有侵權,請聯絡admin@php.cn刪除

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)