php-fpm 是 一個 php FastCGI 進程管理器, php-fpm可以和任何支援遠端FastCGI的web server一起工作。
max_children=40 , 每個children平均佔用20M-30M記憶體,children越多,可以同時接受的併發數量越多,一般children的值是網站最高併發數+浮動值,這值再×記憶體佔用,就是你需要用到的記憶體。
max_requests = N 是指當每個children接受了N次請求以後,就會把自己殺死,然後重新建立一個children。
PV / max_children = 每一個children接受的request次數
常用命令
1.查看php-fpm進程
ps aux | grep -c php-fpm
2.查看php-fpm連接數
netstat -napo |grep "php-fpm" | wc -l
常見問題
1.ARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 92 idle, and 127 total children
注解:負載較高,增加pm.start_servers, or pm.min/max_spare_servers的值,可設置為以下值:
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 30
另外,還有一個原因,就是php代碼由於閉環或是mysql連線時間過長,會導致php-fpm請求一直不釋放,進而使可用的php進程減少,就會引起上面的錯誤提示。解決方法:
request_terminate_timeout = 2s
max_requests = 100
即如果php請求超過了2s,則將其自動關閉。如果某個進程的最大請求數超過了100,也將其關閉。
2.WARNING: [pool www] server reached pm.max_children setting (800), consider raising it
增加pm.max_children到10000
pm.max_children = 10000
3.[22-Aug-2013 04:05:17] WARNING: [pool www] child 4457 exited with code 70 after 0.004114 seconds from start
[22-Aug-2013 04:05:17] NOTICE: [pool www] child 4458 started
php-fpm在啟動後短時間內就被關閉,原因可能是php-fpm進程由於一些原因沒有被釋放,導致php-fpm達到了pm.max_children設置的最大值,所以新的請求產生後,馬上被關閉。解決方法同1
php-fpm 優化
版主: stnet253
誰在線上
正在瀏覽這個版面的使用者:沒有註冊會員 和 1 位訪客