我們常使用php-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_request_shutdown()########因為fpm是常駐進程,所以在###php_request_shutdown()###之後又會從###fcgi_accept_request()###開始迴圈。 #########推薦學習:###php影片教學#######
php_module_startup()
##fcgi_accept_request()
php_request_startup()
fmp_request_executing()
php_execute_script ()
以上是FPM鮮為人知的三種模式的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Dreamweaver Mac版
視覺化網頁開發工具

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

SublimeText3 Linux新版
SublimeText3 Linux最新版

WebStorm Mac版
好用的JavaScript開發工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。