全面剖析PHP-FPM+Nginx通信原理

{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"引言"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"用了這麼久了PHP+Nginx了,你瞭解他們之間的通信原理嗎?這一次做一回真正的PHPer(在"},{"type":"link","attrs":{"href":"https://mp.weixin.qq.com/s/FdVGNKYyMDBaeeLq4HE9Hw","title":""},"content":[{"type":"text","text":"上一篇"}]},{"type":"text","text":"文章裏邊已經全面介紹了CGI、FastCGI、PHP-FPM,所以本文對於這些概念不再介紹的那麼詳細)"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"PHP-FPM"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"PHP-FPM的全稱是"},{"type":"text","marks":[{"type":"strong"}],"text":"PHP FastCGI Process Manager"},{"type":"text","text":",PHP-FPM是FastCGI的實現,並提供了進程管理的功能。FastCGI進程包含master進程和worker進程兩種進程。master進程只有一個,負責監聽端口,接收Nginx的請求,而worker進程則一般有多個(可配置),每個進程內部都嵌入了一個PHP解釋器,是PHP代碼真正執行的地方。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"Nginx"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Nginx (“engine x”) 是一個高性能的HTTP和反向代理服務器,也是一個IMAP/POP3/SMTP服務器。這裏介紹一下什麼是正向代理和反向代理,這個對於我們理解Nginx很重要"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"正向代理"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們那訪問國外的網站爲例,比如訪問Google、Facebook。我們需要藉助vpn才能訪問,我們藉助vpn訪問國外的網站,其實就是個正向代理的過程,上圖:"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/9b/9b81c4f8a69fce2ce909bc90ac878948.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"vpn對於用戶來說,是可以感知到的(因爲用戶需要配置連接),vpn對於google服務器來說,是不可感知的(google服務器只知道有http請求過來)。所以,對於用戶來說可以感知到,而對於服務器來說感知不到的服務器,就是正向代理服務器(vpn)"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"反向代理"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"拿Nginx作爲反向代理服務器實現負載均衡來舉例,假設此時我們訪問百度,看圖:"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/fd/fd9f83270192adbe6ccc360e2c81bf00.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"當用戶訪問百度時,所有的請求會到達一個反向代理服務器,這個反向代理服務器會將請求分發給後邊的某一臺服務器去處理。此時,這個代理服務器其實對用戶來說是不可感知的,用戶感知到的是百度的服務器給自己返回了結果,並不知道代理服務器的存在。也就是說,對於用戶來說不可感知,對於服務器來說是可以感知的,就叫反向代理服務器(Nginx)"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"PHP-FPM+Nginx通信"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"FastCGI致力於減少Web服務器與CGI程序之間互動的開銷,從而使服務器可以同時處理更多的Web請求。與CGI這種爲每個請求創建一個新的進程不同,FastCGI使用持續的進程來處理一連串的請求。"},{"type":"text","marks":[{"type":"strong"}],"text":"這些進程由FastCGI進程管理器管理,而不是web服務器"},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通過圖來理解PHP-FPM和Nginx的通信"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/f5/f5e50d1e22a62a47eabb6678dbaa92c5.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"(1)當Nginx收到http請求(動態請求),它會初始化FastCGI環境。(如果是Apache服務器,則初始化mode"},{"type":"text","marks":[{"type":"italic"}],"text":"fastcgi模塊、如果是Nginx服務器則初始化ngx"},{"type":"text","text":"http_fastcgi_module)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"(2)我們在配置nginx解析php請求時,一般會有這樣一行配置:"}]},{"type":"codeblock","attrs":{"lang":""},"content":[{"type":"text","text":"fastcgi_pass 127.0.0.1:9000;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"或者長這樣:"}]},{"type":"codeblock","attrs":{"lang":""},"content":[{"type":"text","text":"fastcgi_pass unix:/tmp/php-cgi.sock;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"它其實是Nginx和PHP-FPM一個通信載體(或者說通信方式),目的是爲了讓Nginx知道,收到動態請求之後該往哪兒發。(關於這兩種配置的區別,後邊會專門介紹)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"(3)Nginx將請求採用socket的方式轉給FastCGI主進程"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"(4)FastCGI主進程選擇一個空閒的worker進程連接,然後Nginx將CGI環境變量和標準輸入發送該worker進程(php-cgi)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"(5)worker進程完成處理後將標準輸出和錯誤信息從"},{"type":"text","marks":[{"type":"strong"}],"text":"同一socket連接"},{"type":"text","text":"返回給Nginx"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"(6)worker進程關閉連接,等待下一個連接"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"不從配置的角度,再描述一下PHP和Nginx的通信"}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們知道Nginx也是有master和worker進程的,worker進程直接處理每一個網絡請求"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"其實在Nginx+PHP的架構裏邊,php可以看做是一個cgi程序的角色,因此出現了php-fpm進程管理器來處理這些php請求。php-fpm和nginx一樣,也會監聽端口(通過nginx.conf裏的配置我們知道,nginx默認監聽8080端口,php-fpm默認監聽9000端口),並且有master和worker進程,worker負責處理每一個php請求"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"關於fastcgi:fastcgi是一個協議。市面上有多種實現了fastcgi協議的進程管理器,php-fpm就是其中的一種。php-fpm作爲一種fastcgi進程管理服務,會監聽端口,一般默認監聽9000端口,並且是監聽本機,也就是隻接收來自本機的端口請求"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"關於fastcgi的配置文件,目前fastcgi的配置文件一般放在nginx.conf同級目錄下,配置文件形式,一般有兩種:"}]}]}]},{"type":"codeblock","attrs":{"lang":""},"content":[{"type":"text","text":"fastcgi.conf和 fastcgi_params。\n不同的nginx版本會有不同的配置文件,這兩個配置文件有一個非常重要的區別:fastcgi_parames文件中缺少下列配置:\nfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們可以打開fastcgi_params文件加上上述行,也可以在要使用配置的地方動態添加。使得該配置生效"}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"當需要處理php請求時,nginx的worker進程會將請求移交給php-fpm的worker進程進行處理,也就是最開頭所說的nginx調用了php,其實嚴格得講是nginx間接調用php(反向代理的方式)"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我本機配置了能正常解析php程序的nginx配置,介紹一下每一行配置的含義"}]},{"type":"codeblock","attrs":{"lang":""},"content":[{"type":"text","text":"server{\nlisten 8080;\nindex index.php\nroot /work/html/;\nlocation ~ [^/]\\.php(/|$)\n{\nroot /work/html/;\nfastcgi_pass 127.0.0.1:9000;\nfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\ninclude fastcgi_params;\n}\naccess_log /work/html/logs/test.log;\n}"}]},{"type":"numberedlist","attrs":{"start":"1","normalizeStart":1},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"第一個大括號 server{ }:代表一個獨立的server"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"listen 8080:代表該server監聽8080端口"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"location ~ [^/]\\.php(/|$){ }:代表一個能匹配對應uri的location,用於匹配一類uri,並對所匹配的uri請求做自定義的邏輯、配置。這裏的location,匹配了所有帶.php的uri請求,例如:http://192.168.244.128:8011/test.php/asdasd http://192.168.244.128:8011/index.php等"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null},"content":[{"type":"text","text":"root /work/html/:請求資源根目錄,告訴匹配到該location下的uri到/work/html/文件夾下去尋找同名資源"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":5,"align":null,"origin":null},"content":[{"type":"text","text":"fastcgi_pass 127.0.0.1:9000:這行代碼的意思是,將進入到該location內的uri請求看做是cgi程序,並將請求發送到9000端口,交由php-fpm處理(php-fpm配置中會看見它監聽了此端口)"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":6,"align":null,"origin":null},"content":[{"type":"text","text":"fastcgi"},{"type":"text","marks":[{"type":"italic"}],"text":"param SCRIPT"},{"type":"text","text":"FILENAME"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"fastcgi"},{"type":"text","marks":[{"type":"italic"}],"text":"script"},{"type":"text","text":"name; :這行配置意思是:動態添加了一行fastcgi配置,配置內容爲SCRIPT"},{"type":"text","marks":[{"type":"italic"}],"text":"FILENAME,告知管理進程,cgi腳本名稱。由於我的nginx中只有fastcgi"},{"type":"text","text":"params文件,沒有fastcgi.conf文件,所以要使php-fpm知道SCRIPT_FILENAME的具體值,就必須要動態的添加這行配置"}]},{"type":"numberedlist","attrs":{"start":"7","normalizeStart":"7"},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":7,"align":null,"origin":null},"content":[{"type":"text","text":"include fastcgi_params; 引入fastcgi配置文件"}]}]}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"fastcgi_pass"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Nginx和PHP-FPM的進程間通信有兩種方式,一種是"},{"type":"text","marks":[{"type":"strong"}],"text":"TCP Socket"},{"type":"text","text":",一種是"},{"type":"text","marks":[{"type":"strong"}],"text":"Unix Socket"},{"type":"text","text":"."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Tcp Socket方式是IP加端口,可以跨服務器.而UNIX Socket不經過網絡,只能用於Nginx跟PHP-FPM都在同一服務器的場景,用哪種取決於你的PHP-FPM配置"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Tcp Socket方式:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"nginx.conf中配置:fastcgi_pass 127.0.0.1:9000;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"php-fpm.conf中配置:listen=127.0.0.1:9000;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Unix Domain Socket方式:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"nginx.conf中配置:fastcgi_pass unix:/tmp/php-fpm.sock;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"php-fpm中配置:listen = /tmp/php-fpm.sock;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"(php-fpm.sock是一個文件,由php-fpm生成)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"舉例:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"兩種通信配置方式,Nginx和PHP-FPM的通信過程如下:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Tcp Socket:"}]},{"type":"codeblock","attrs":{"lang":""},"content":[{"type":"text","text":"Nginx <=> socket <=> TCP/IP <=> socket <=> PHP-FPM"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"(上邊畫Nginx和PHP-FPM通信的圖時就是這種方式,"},{"type":"text","marks":[{"type":"strong"}],"text":"這種情況是Nginx和PHP-FPM在同一臺機器上"},{"type":"text","text":")"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"看一下Nginx和PHP-FPM不在同一臺機器上的情況:"}]},{"type":"codeblock","attrs":{"lang":""},"content":[{"type":"text","text":"Nginx <=> socket <=> TCP/IP <=> 物理層 <=> 路由器 <=> 物理層 <=> TCP/IP <=> socket <=> PHP-FPM"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Unix Socket:"}]},{"type":"codeblock","attrs":{"lang":""},"content":[{"type":"text","text":"Nginx <=> socket <=> PHP-FPM"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"include fastcgi_params;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在nginx中有很多的fasgcgi"},{"type":"text","marks":[{"type":"italic"}],"text":"*的配置,更多的配置可以在nginx.conf的同級目錄中看到,在fastcgi.conf和fastcgi"},{"type":"text","text":"params中,這兩個的區別,上邊有說明。看一下里邊的內容:"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/5d/5d145e18bfa04990f001a9c0a6640307.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這裏邊的內容都會被傳遞給PHP-FPM所管理的fastcgi進程。爲什麼會傳遞這些呢?相信大家都用過$"},{"type":"text","marks":[{"type":"italic"}],"text":"SERVER這個全局變量,這裏邊的值就是從此配置中拿到的。我們可以在fastcgi"},{"type":"text","text":"params中看到REMOTE"},{"type":"text","marks":[{"type":"italic"}],"text":"ADDR,就是客戶端地址,PHP之所以能拿到客戶端信息,就是因爲Nginx的配置中的fastcgi"},{"type":"text","text":"params。更多ngx"},{"type":"text","marks":[{"type":"italic"}],"text":"http"},{"type":"text","text":"fastcgi"},{"type":"text","marks":[{"type":"italic"}],"text":"module模塊的內容,可以看官方文檔:http://nginx.org/en/docs/http/ngx"},{"type":"text","text":"http_fastcgi_module.html"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"php-fpm.conf配置"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"熟悉php-fpm的配置,能幫助我們優化服務器性能"}]},{"type":"codeblock","attrs":{"lang":""},"content":[{"type":"text","text":"emergency_restart_threshold = 60\nemergency_restart_interval = 60s"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"表示在emergency"},{"type":"text","marks":[{"type":"italic"}],"text":"restart"},{"type":"text","text":"interval所設值內出現SIGSEGV或者SIGBUS錯誤的php-cgi進程數如果超過 emergency"},{"type":"text","marks":[{"type":"italic"}],"text":"restart"},{"type":"text","text":"threshold個,php-fpm就會優雅重啓。這兩個選項一般保持默認值"}]},{"type":"codeblock","attrs":{"lang":""},"content":[{"type":"text","text":"process_control_timeout = 0"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"設置子進程接受主進程複用信號的超時時間. 可用單位: s(秒), m(分), h(小時), 或者 d(天) 默認單位: s(秒). 默認值: 0."}]},{"type":"codeblock","attrs":{"lang":""},"content":[{"type":"text","text":"listen = 127.0.0.1:9000"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"fpm監聽端口,即nginx中php處理的地址,一般默認值即可。可用格式爲: ‘ip:port’, ‘port’, ‘/path/to/unix/socket’. 每個進程池都需要設置."}]},{"type":"codeblock","attrs":{"lang":""},"content":[{"type":"text","text":"request_slowlog_timeout = 10s\n#當一個請求該設置的超時時間後,就會將對應的PHP調用堆棧信息完整寫入到慢日誌中. 設置爲 ’0′ 表示 ‘Off’\nslowlog = log/$pool.log.slow\n慢請求的記錄日誌,配合request_slowlog_timeout使用"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"下邊幾個配置參數比較重要:"}]},{"type":"codeblock","attrs":{"lang":""},"content":[{"type":"text","text":"pm\npm指的是process manager,指定進程管理器如何控制子進程的數量,它爲必填項,支持3個值\n(1)static: 使用固定的子進程數量,由pm.max_children指定(可以同時存活的子進程的最大數量)\n(2)dynamic:基於下面的參數動態的調整子進程的數量,至少有一個子進程(會使用下邊幾個配置)\npm.start_servers: 啓動時創建的子進程數量,默認值爲min_spare_servers + max_spare_servers - min_spare_servers) / 2\npm.min_spare_servers: 空閒狀態的子進程的最小數量,如果不足,新的子進程會被自動創建\npm.max_spare_servers: 空閒狀態的子進程的最大數量,如果超過,一些子進程會被殺死\n(3)ondemand: 啓動時不會創建子進程,當新的請求到達時才創建,有下邊兩個配置\npm.max_children\npm.process_idle_timeout 子進程的空閒超時時間,如果超時時間到沒有新的請求可以服務,則會被殺死\n區別:\n如果pm設置爲 static,那麼其實只有pm.max_children這個參數生效。系統會開啓設置數量的php-fpm進程\n如果pm設置爲 dynamic,那麼pm.max_children參數失效,後面3個參數生效\n系統會在php-fpm運行開始 的時候啓動pm.start_servers個php-fpm進程,\n然後根據系統的需求動態在pm.min_spare_servers和pm.max_spare_servers之間調整php-fpm進程數\n還有一個比較重要的配置:\npm.max_requests\n每一個子進程的最大請求服務數量,如果超過了這個值,該子進程會被自動重啓。在解決第三方庫的內存泄漏問題時,這個參數會很有用。默認值爲0,指子進程可以持續不斷的服務請求"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"PHP-FPM進程池"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"php-fpm.conf中默認配置了一個進程池,我們可以打開我們的php-fpm.conf看一下,下邊是我的:"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/61/6105c98e59d57b7c2b9e4ab1550f5359.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"現在我們執行一下:ps -aux|grep php-fpm"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/f7/f756b36a7b444d37f5cf3d7820696a3d.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"會看見有一個master,10個worker進程,和我們配置的一樣(www爲進程池名)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"想配置多個,這樣做即可:"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/5c/5ceb1954b5c8938383c42010552cd513.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在nginx中fastcgi_pass這個地方配置使用哪個進程池即可"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"參考:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"https://www.php.cn/php-weizijiaocheng-393152.html"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"https://www.cnblogs.com/skynet/p/4173450.html"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"https://blog.csdn.net/afring/article/details/93880216"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"https://www.cnblogs.com/ahaii/p/5776809.html"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/4a/4ab4089bfc072c275dce3d15e518bf56.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章