FPM鮮為人知的三種模式
我們常使用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 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

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

熱門話題

php7.0安裝mongo擴充的方法:1、建立mongodb使用者群組和使用者;2、下載mongodb原始碼包,並將原始碼包放到“/usr/local/src/”目錄下;3、進入“src/”目錄;4、解壓縮原始碼包;5、建立mongodb檔案目錄;6、將檔案複製到「mongodb/」目錄;7、建立mongodb設定檔並修改設定即可。

在php5中,我們可以使用fsockopen()函數來偵測TCP埠。這個函數可以用來開啟一個網路連接和進行一些網路通訊。但是在php7中,fsockopen()函數可能會遇到一些問題,例如無法開啟連接埠、無法連接到伺服器等。為了解決這個問題,我們可以使用socket_create()函數和socket_connect()函數來偵測TCP埠。

解決 PHP 7.0 中插件未顯示已安裝問題的方法:檢查插件配置並啟用插件。重新啟動 PHP 以套用配置變更。檢查插件檔案權限,確保其正確。安裝遺失的依賴項,以確保插件正常運作。如果其他步驟都失敗,則重建 PHP。其他可能原因包括外掛程式版本不相容、載入錯誤版本或 PHP 配置問題。

PHP伺服器環境常見的解決方法包括:確保已安裝正確的PHP版本和已複製相關檔案到模組目錄。暫時或永久停用SELinux。檢查並配置PHP.ini,確保已新增必要的擴充功能和進行正確設定。啟動或重新啟動PHP-FPM服務。檢查DNS設定是否有解析問題。

php7.0安裝部署的方法:1、到PHP官網下載與本機系統對應的安裝版本;2、將下載的zip檔案解壓縮到指定目錄;3、開啟命令列窗口,在「E:\php7」目錄下運行“php -v”命令即可。

解決Ubuntu缺少PHP-FPM的問題,需要具體程式碼範例在Ubuntu系統中,安裝和設定PHP-FPM是常見的操作,但有時候在安裝過程中會出現缺少PHP-FPM的問題。本文將詳細介紹如何解決這個問題,並提供具體的程式碼範例來幫助您完成安裝和設定。 1.檢查PHP-FPM是否已安裝首先,使用下列指令檢查系統中是否已經安裝了PHP-FPM:dpkg-l|gr

如何在系統重啟後自動設置unixsocket的權限每次系統重啟後,我們都需要執行以下命令來修改unixsocket的權限:sudo...

解決Linux環境下PHP7-FPM啟動失敗的方法在使用Linux伺服器建立網站或應用程式時,PHP7-FPM是常用的PHPFastCGI進程管理器。但是有時會遇到PHP7-FPM啟動失敗的問題,這可能會導致網站無法正常存取。在本文中,我們將介紹一些常見的解決方法,並提供具體的程式碼範例。希望這些資訊能幫助你快速解決PHP7-FPM啟動失敗的情況。檢查
