首先在nginx.conf 中配置server 127.0.0.1 具体配置略 然后添加

        location = /status {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }

找到php-fpm的配置文件 php-fpm.d/www.conf,

; 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 = dynamic

php-fpm有三种进程管理模式:static、dynamic、ondemand static:设置固定数量的进程 dynamic:由以下命令决定动态设置子进程的数量,

  1. pm.max_children:最大子进程数量
  2. pm.start_servers:启动时的子进程数量,默认为min_spare_servers + (max_spare_servers - min_spare_servers) / 2
  3. pm.min_spare_servers:空闲子进程最小数量,如果低于这个值,则php-fpm会创建新的子进程
  4. pm.max_spare_servers:空闲子进程最大数量,如果空闲数大于这个值则php-fpm会kill部分子进程

ondemand:按需创建(暂时这么翻译吧),启动时不会设置子进程,当有新的连接创建时,才会产生新的子进程,有以下参数:

  1. pm.max_children:同时可存活的最大进程数
  2. pm.process_idle_timeout:进程最长等待时间

在www.conf开启以上各参数后,重启php-fpm,reload nginx.conf,浏览器中输入:

http://127.0.0.1/status?full

输出:

pool:                 www
process manager:      dynamic
start time:           01/Apr/2018:21:36:30 +0800
start since:          2967
accepted conn:        29
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       1
active processes:     1
total processes:      2
max active processes: 1
max children reached: 0
slow requests:        0

************************
pid:                  47524
state:                Running
start time:           01/Apr/2018:21:36:30 +0800
start since:          2967
requests:             15
request duration:     13733
request method:       GET
request URI:          /status?full
content length:       0
user:                 -
script:               -
last request cpu:     0.00
last request memory:  0

************************
pid:                  47525
state:                Idle
start time:           01/Apr/2018:21:36:30 +0800
start since:          2967
requests:             14
request duration:     844
request method:       GET
request URI:          /status?html&full
content length:       0
user:                 -
script:               -
last request cpu:     0.00
last request memory:  2097152