全面剖析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}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章