189 8069 5689

php-fpm的pool、 php-fpm慢执行日志、 php-fpm进程管理

php-fpm的pool

● php-fpm的pool,在ps aux的时候在右侧可以看到那一列,php-fpm的pool,也就是php-fpm的池子.

成都创新互联公司是一家集网站建设,翠屏企业网站建设,翠屏品牌网站建设,网站定制,翠屏网站建设报价,网络营销,网络优化,翠屏网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

●在php-fpm.conf里面定义了一个池子,支持定义多个池子,每个池子可以监听不同sock或tcp.例如Nginx有多个站点,每个站点都可以使用不同pool.如果Nginx有多个站点都使用一个pool的话,假如出现了502的,出现在502状态码,有可能是因为php资源不够,那么所有的站点都502,但是如果Nginx每个站点使用单独pool,其中一个站点502了,但不会影响到其他站点.

● 新增加一个pool

[root@root-01 etc]# vim php-fpm.conf [global] pid = /usr/local/php-fpm/var/run/php-fpm.pid error_log = /usr/local/php-fpm/var/log/php-fpm.log [www] #listen = /tmp/php-fcgi.sock listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 [Anna.com] --->新增加的pool listen = /tmp/Anna.sock #listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024

● 保存退出,检查一下语法是否有误,并重启php-fpm

[root@root-01 ~]# /usr/local/php-fpm/sbin/php-fpm -t [16-Aug-2017 10:41:56] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful [root@root-01 ~]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done

● 重启php-fpm后ps aux |grep php-fpm,会发现多了Anna.com的pool

[root@root-01 ~]# ps aux |grep php-fpm root 2871 7.0 0.4 224400 4956 ? Ss 10:44 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 2872 0.0 0.4 224340 4640 ? S 10:44 0:00 php-fpm: pool www php-fpm 2873 0.0 0.4 224340 4640 ? S 10:44 0:00 php-fpm: pool www php-fpm 2874 0.0 0.4 224340 4640 ? S 10:44 0:00 php-fpm: pool www php-fpm 2875 0.0 0.4 224340 4640 ? S 10:44 0:00 php-fpm: pool www php-fpm 2876 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool www php-fpm 2877 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool www php-fpm 2878 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool www php-fpm 2879 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool www php-fpm 2880 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool www php-fpm 2881 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool www php-fpm 2882 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool www php-fpm 2883 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool www php-fpm 2884 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool www php-fpm 2885 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool www php-fpm 2886 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool www php-fpm 2887 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool www php-fpm 2888 0.0 0.4 224340 4648 ? S 10:44 0:00 php-fpm: pool www php-fpm 2889 0.0 0.4 224340 4648 ? S 10:44 0:00 php-fpm: pool www php-fpm 2890 0.0 0.4 224340 4648 ? S 10:44 0:00 php-fpm: pool www php-fpm 2891 0.0 0.4 224340 4648 ? S 10:44 0:00 php-fpm: pool www php-fpm 2892 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2893 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2894 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2895 0.0 0.4 224340 4644 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2896 0.0 0.4 224340 4648 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2897 0.0 0.4 224340 4648 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2898 0.0 0.4 224340 4648 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2899 0.0 0.4 224340 4648 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2900 0.3 0.4 224340 4648 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2901 0.0 0.4 224340 4648 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2902 0.0 0.4 224340 4648 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2903 0.0 0.4 224340 4648 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2904 0.0 0.4 224340 4652 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2905 0.0 0.4 224340 4652 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2906 0.0 0.4 224340 4652 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2907 0.0 0.4 224340 4652 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2908 0.0 0.4 224340 4652 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2909 0.0 0.4 224340 4652 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2910 0.0 0.4 224340 4652 ? S 10:44 0:00 php-fpm: pool Anna.com php-fpm 2911 0.0 0.4 224340 4652 ? S 10:44 0:00 php-fpm: pool Anna.com root 2913 0.0 0.0 112664 964 pts/2 S+ 10:44 0:00 grep --color=auto php-fpm

● 现在有两个pool,在test.conf.com站点监听是127.0.0.1:9000,现在就把aaa.com.conf定义为Anna.com,这样的话这样两个站点就隔离开了.

[root@root-01 vhost]# vim aaa.com.conf server { listen 80 default_server; server_name aaa.com; index index.html index.htm index.php; root /data/www/default; location ~ .php$ { include fastcgi_params; fastcgi_pass unix:/tmp/Anna.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/www/default$fastcgi_script_name; } } 说明 假如test.conf.com很忙,请求量很大,将php-fpm进程耗尽,最多可以启动50个进程,所有的进程都在忙,当再来一个新的请求的时候,就会出现了502,因为没有多余的php-fpm进程提供服务.但aaa.com.conf并不会受影响,因为使用的是另外一个pool,这就是建立多个pool的好处.

●在/usr/local/nginx/conf/nginx.conf里面定义了include vhost/.conf,在php-fpm.conf也是支持的,现在php-fpm.conf主配置文件里面也加include = etc/php-fpm.d/.conf.

[root@root-01 ~]# vim /usr/local/php-fpm/etc/php-fpm.conf [global] pid = /usr/local/php-fpm/var/run/php-fpm.pid [global] pid = /usr/local/php-fpm/var/run/php-fpm.pid error_log = /usr/local/php-fpm/var/log/php-fpm.log include = etc/php-fpm.d/*.conf

● 在/usr/local/php-fpm/etc/目录下面创建配置文件目录和子配置文件.

[root@root-01 ~]# cd /usr/local/php-fpm/etc/ [root@root-01 etc]# ls pear.conf php-fpm.conf php-fpm.conf2 php.ini [root@root-01 etc]# mkdir php-fpm.d [root@root-01 etc]# cd php-fpm.d [root@root-01 php-fpm.d]# touch www.conf [root@root-01 php-fpm.d]# touch Anna.conf

● 把/usr/local/php-fpm/etc/php-fpm.conf 里面的两个pool分别剪贴到www.conf&Anna.conf

[root@root-01 php-fpm.d]# vim www.conf [www] #listen = /tmp/php-fcgi.sock listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 [root@root-01 php-fpm.d]# vim Anna.conf [Anna.com] listen = /tmp/Anna.sock #listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 [root@root-01 php-fpm.d]# ls Anna.conf www.conf

● 检查语法是否有误&重启php-fpm,在ps aux |grep php-fpm查看是效果是一样的,只不过这样会更加清晰.

[root@root-01 php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t [16-Aug-2017 11:31:37] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful [root@root-01 php-fpm.d]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done [root@root-01 php-fpm.d]# ps aux |grep php-fpm root 2967 0.2 0.4 224428 4956 ? Ss 11:32 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 2968 0.0 0.4 224368 4636 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2969 0.0 0.4 224368 4636 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2970 0.0 0.4 224368 4636 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2971 0.0 0.4 224368 4636 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2972 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2973 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2974 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2975 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2976 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2977 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2978 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2979 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2980 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2981 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2982 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2983 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2984 0.0 0.4 224368 4644 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2985 0.0 0.4 224368 4644 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2986 0.0 0.4 224368 4644 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2987 0.0 0.4 224368 4644 ? S 11:32 0:00 php-fpm: pool Anna.com php-fpm 2988 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool www php-fpm 2989 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool www php-fpm 2990 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool www php-fpm 2991 0.0 0.4 224368 4640 ? S 11:32 0:00 php-fpm: pool www php-fpm 2992 0.0 0.4 224368 4644 ? S 11:32 0:00 php-fpm: pool www php-fpm 2993 0.0 0.4 224368 4644 ? S 11:32 0:00 php-fpm: pool www php-fpm 2994 0.0 0.4 224368 4644 ? S 11:32 0:00 php-fpm: pool www php-fpm 2995 0.0 0.4 224368 4644 ? S 11:32 0:00 php-fpm: pool www php-fpm 2996 0.0 0.4 224368 4644 ? S 11:32 0:00 php-fpm: pool www php-fpm 2997 0.0 0.4 224368 4644 ? S 11:32 0:00 php-fpm: pool www php-fpm 2998 0.0 0.4 224368 4644 ? S 11:32 0:00 php-fpm: pool www php-fpm 2999 0.0 0.4 224368 4644 ? S 11:32 0:00 php-fpm: pool www php-fpm 3000 0.0 0.4 224368 4648 ? S 11:32 0:00 php-fpm: pool www php-fpm 3001 0.0 0.4 224368 4648 ? S 11:32 0:00 php-fpm: pool www php-fpm 3002 0.0 0.4 224368 4648 ? S 11:32 0:00 php-fpm: pool www php-fpm 3003 0.0 0.4 224368 4648 ? S 11:32 0:00 php-fpm: pool www php-fpm 3004 0.0 0.4 224368 4648 ? S 11:32 0:00 php-fpm: pool www php-fpm 3005 0.0 0.4 224368 4648 ? S 11:32 0:00 php-fpm: pool www php-fpm 3006 0.0 0.4 224368 4648 ? S 11:32 0:00 php-fpm: pool www php-fpm 3007 0.0 0.4 224368 4648 ? S 11:32 0:00 php-fpm: pool www root 3009 0.0 0.0 112664 964 pts/2 S+ 11:32 0:00 grep --color=auto php-fpm php-fpm慢执行日志

前言:php-fpm慢执行日志,在日常工作中使用的非常多,可以帮助我们快速追查到问题点.

● 做PHP网站,建议使用lnmp,其中有一个原因就是我们可以去分析PHP的慢执行日志,为什么要分析PHP的慢执行日志呢?在运维工作中,经常会遇到一个很让头痛的问题,公司老板或客户经常反馈公司网站访问慢.为什么会慢?运维人员要知道根本原因,要知道慢在哪个地方.PHP网站是有办法指定慢在哪里.

服务器负载高,我们可以使用free,top等命令去查看,可以知道到底是哪个进程导致负载高. 种种迹象表明php-fpm进程占用了很多资源,但是并不知道为什么php-fpm在做什么,那么有php慢执行日志我们就可以查看到问题点,所以php慢执行日志非常重要.

● 现在针对ww.conf做一些配置

[root@root-01 php-fpm.d]# vim www.conf [www] #listen = /tmp/php-fcgi.sock listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 加入这行配置: request_slowlog_timeout = 1 --->请求慢日志超过1秒钟,就会记录日志 slowlog = /usr/local/php-fpm/var/log/www.slow.log --->定义日志路径

● 保存退出后,检查语法是否有误,并重新加载php-fpm,在查看/usr/local/php-fpm/var/log/目录下是否有生成www.slow.log日志文件

[root@root-01 ~]# /etc/init.d/php-fpm reload Reload service php-fpm done [root@root-01 ~]# ls /usr/local/php-fpm/var/log/www.slow.log /usr/local/php-fpm/var/log/www.slow.log [root@root-01 ~]# ls /usr/local/php-fpm/var/log/ php-fpm.log www.slow.log

●模拟一个慢执行的PHP,写一个脚本,www这个pool是test.com.conf站点在使用,所以要针对这个站点做操作. 在/data/www/test.com/目录下写一个sleep.php的脚本

[root@root-01 ~]# vim /data/www/test.com/sleep.php ~ 说明 这脚本是要在执行的停2秒,因为在配置www.conf文件请求慢日志超过1秒钟,就会记录日志.

● 使用curl来测试一下,然后再查看www.slow.log日志

[root@root-01 ~]# curl -x127.0.0.1:80 test.com/sleep.php test slow logdone[root@root-01 ~]# [root@root-01 ~]# cat /usr/local/php-fpm/var/log/www.slow.log [16-Aug-2017 12:30:32] [pool www] pid 3068 script_filename = /data/www/test.com/sleep.php [0x00007f40307e52e8] sleep() /data/www/test.com/sleep.php:3 说明 script_filename = /data/www/test.com/sleep.php ---> 这行是告诉我们执行慢慢在哪里. [0x00007f40307e52e8] sleep() /data/www/test.com/sleep.php:3 -->慢在具体哪一行. 说明 这就是php慢执行日志的好处. 12.23 open_basedir

前言:open_basedir的目的就是安全,

● php-fpm也是可以定义open_basedir,之前讲过在php.ini中去定义,如果服务器上有多个网站,在php.ini里面去定义就不合适了.要么在Apache虚拟主机里面配置,要么在php-fpm里面配置,我们可以根据不同的pool去定义open_basedir

● 现在去php-fpm.d下的www.conf (www pool)定义open_basedir

[root@root-01 ~]# cd /usr/local/php-fpm/etc/php-fpm.d root@root-01 php-fpm.d]# vim www.conf [www] #listen = /tmp/php-fcgi.sock #listen = /tmp/php-fcgi.sock listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 request_slowlog_timeout = 1 slowlog = /usr/local/php-fpm/var/log/www.slow.log 加入这行: php_admin_value[open_basedir]=/data/www/test.com:/tmp/

保存退出后,重启一下php-fpm

[root@root-01 php-fpm.d]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done

使用curl来测试一下,状态码200

[root@root-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php -I HTTP/1.1 200 OK Server: nginx/1.12.1 Date: Wed, 16 Aug 2017 05:51:06 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.6.30

● 在php.ini配置文件里面的display_errors = off 一般在线上使用都是off,这样做事为了不能让别人通过浏览器看到错误信息。而错误日志是定义在服务器的某个文件里

第1步:进入php.ini,把display_errors设置为 off

第2步:log_errors设为On

第3步:在error_log = syslog下面添加日志路径 error_log = /usr/local/php-fpm/var/log/php_errors.log

第4步:定义error_reporting(日志级别),搜索 Common Values:添加error_reportinr = E_ALL. 然后把error_reportinr = E_ALL & ~E_DEPRECATED & ~E_STRICT 使用;注释掉.

● 现在去/usr/local/php-fpm/var/log/目录下手动创建php_errors.log文件,并且把权限设置为777,目的是为了能够正常的写入内容.

[root@root-01 ~]# cd /usr/local/php-fpm/var/log/ [root@root-01 log]# touch php_errors.log [root@root-01 log]# ls php_errors.log php-fpm.log www.slow.log [root@root-01 log]# chmod 777 php_errors.log

● 进入www.conf,把定义open_basedir的路径故意定义错

[root@root-01 php-fpm.d]# vim www.conf [www] #listen = /tmp/php-fcgi.sock listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 request_slowlog_timeout = 1 slowlog = /usr/local/php-fpm/var/log/www.slow.log php_admin_value[open_basedir]=/data/www/Anna.com:/tmp/ -->原本是test.com,现在把更改为Anna.com

● 重启php-fpm

[root@root-01 php-fpm.d]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done

● 现在curl来测试访问,结果显示404

[root@root-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php -I HTTP/1.1 404 Not Found Server: nginx/1.12.1 Date: Wed, 16 Aug 2017 06:29:23 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.6.30

● 现在来查看一下错误日志

[root@root-01 log]# cat php_errors.log [16-Aug-2017 06:29:23 UTC] PHP Warning: Unknown: open_basedir restriction in effect. File(/data/www/test.com/sleep.php) is not within the allowed path(s): (/data/www/Anna.com:/tmp/) in Unknown on line 0 [16-Aug-2017 06:29:23 UTC] PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0 说明 open_basedir有限制,限制在(/data/www/Anna.com),而/data/www/test.com/sleep.php是位未知路径.

● 把www.conf open——basedir路更改为正确的,在使用curl来访问就显示200正常.

[root@root-01 php-fpm.d]# vim www.conf [www] #listen = /tmp/php-fcgi.sock listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 request_slowlog_timeout = 1 slowlog = /usr/local/php-fpm/var/log/www.slow.log php_admin_value[open_basedir]=/data/www/test.com:/tmp/ [root@root-01 php-fpm.d]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done [root@root-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php -I HTTP/1.1 200 OK Server: nginx/1.12.1 Date: Wed, 16 Aug 2017 06:43:32 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.6.30 php-fpm进程管理

www.conf 里面有以下配置:

pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 pm = dynamic 定义php-fpm的子进程启动模式,dynamic为动态模式;一开始只是启动少量的子进程,根据实际需要,动态地增加或者减少子进程,最多不会超过pm.max_children 定义的数值 pm.start_servers 针对dynamic模式,定义php-fpm服务在启动服务时产生的子进程数量. pm.min_spare_servers 针对dynamic模式,定义在空闲时段子进程数的最少数量,如果达到这个数量时,php-fpm会自动生成新的子进程. pm.max_spare_servers 针对dynamic模式,定义一个子进程最多处理的请求数,也就是说在一个pho-fpm的子进程中最多可以处理这么请求,当达到这个数值时,它会自动退出. 还有一种模式是static(静态的),如果把pm = dynamic更改为pm = static,那么只生效pm.max_children,一次性启动这么多,不会减少也不会增加其他的pm.start_servers;pm.min_spare_servers;pm.max_spare_servers;pm.max_requests 都不会再生效.

● 把www.conf更为static

[root@root-01 php-fpm.d]# vim www.conf [www] #listen = /tmp/php-fcgi.sock listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic #pm = static pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 request_slowlog_timeout = 1 slowlog = /usr/local/php-fpm/var/log/www.slow.log php_admin_value[open_basedir]=/data/www/test.com:/tmp/

●保存退出后,重启php-fpm,再使用ps aux |grep php-fpm就可以看到一次性启动50个子进程

[root@root-01 php-fpm.d]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done [root@root-01 php-fpm.d]# ps aux |grep php-fpm root 3615 1.3 0.4 224428 4984 ? Ss 15:24 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 3616 0.0 0.4 224368 4636 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3617 0.0 0.4 224368 4636 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3618 0.0 0.4 224368 4636 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3619 0.0 0.4 224368 4636 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3620 0.0 0.4 224368 4640 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3621 0.0 0.4 224368 4640 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3622 0.0 0.4 224368 4640 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3623 0.0 0.4 224368 4640 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3624 0.0 0.4 224368 4640 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3625 0.0 0.4 224368 4640 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3626 0.0 0.4 224368 4640 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3627 0.0 0.4 224368 4640 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3628 0.0 0.4 224368 4640 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3629 0.0 0.4 224368 4640 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3630 0.0 0.4 224368 4644 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3631 0.0 0.4 224368 4644 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3632 0.0 0.4 224368 4644 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3633 0.0 0.4 224368 4644 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3634 0.0 0.4 224368 4644 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3635 0.0 0.4 224368 4644 ? S 15:24 0:00 php-fpm: pool Anna.com php-fpm 3636 0.0 0.4 224368 4640 ? S 15:24 0:00 php-fpm: pool www php-fpm 3637 0.0 0.4 224368 4640 ? S 15:24 0:00 php-fpm: pool www php-fpm 3638 0.0 0.4 224368 4640 ? S 15:24 0:00 php-fpm: pool www php-fpm 3639 0.0 0.4 224368 4640 ? S 15:24 0:00 php-fpm: pool www php-fpm 3640 0.0 0.4 224368 4644 ? S 15:24 0:00 php-fpm: pool www php-fpm 3641 0.0 0.4 224368 4644 ? S 15:24 0:00 php-fpm: pool www php-fpm 3642 0.0 0.4 224368 4644 ? S 15:24 0:00 php-fpm: pool www php-fpm 3643 0.0 0.4 224368 4644 ? S 15:24 0:00 php-fpm: pool www php-fpm 3644 0.0 0.4 224368 4644 ? S 15:24 0:00 php-fpm: pool www php-fpm 3645 0.0 0.4 224368 4644 ? S 15:24 0:00 php-fpm: pool www php-fpm 3646 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3647 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3648 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3649 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3650 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3651 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3652 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3653 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3654 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3655 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3656 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3657 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3658 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3659 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3660 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3661 0.0 0.4 224368 4648 ? S 15:24 0:00 php-fpm: pool www php-fpm 3662 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3663 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3664 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3665 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3666 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3667 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3668 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3669 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3670 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3671 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3672 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3673 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3674 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3675 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3676 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3677 0.0 0.4 224368 4652 ? S 15:24 0:00 php-fpm: pool www php-fpm 3678 0.0 0.4 224368 4656 ? S 15:24 0:00 php-fpm: pool www php-fpm 3679 0.0 0.4 224368 4656 ? S 15:24 0:00 php-fpm: pool www php-fpm 3680 0.0 0.4 224368 4656 ? S 15:24 0:00 php-fpm: pool www php-fpm 3681 0.0 0.4 224368 4656 ? S 15:24 0:00 php-fpm: pool www php-fpm 3682 0.0 0.4 224368 4852 ? S 15:24 0:00 php-fpm: pool www php-fpm 3683 0.0 0.4 224368 4852 ? S 15:24 0:00 php-fpm: pool www php-fpm 3684 0.0 0.4 224368 4848 ? S 15:24 0:00 php-fpm: pool www php-fpm 3685 0.0 0.4 224368 4836 ? S 15:24 0:00 php-fpm: pool www root 3687 0.0 0.0 112664 964 pts/2 S+ 15:24 0:00 grep --color=auto php-fpm

再把www.conf更改为dynamic,再来查看的的时候就只有20个子进程

[root@root-01 php-fpm.d]# vim www.conf [www] #listen = /tmp/php-fcgi.sock listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic #pm = static pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 request_slowlog_timeout = 1 slowlog = /usr/local/php-fpm/var/log/www.slow.log php_admin_value[open_basedir]=/data/www/test.com:/tmp/ [root@root-01 php-fpm.d]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done [root@root-01 php-fpm.d]# ps aux |grep php-fpm root 3697 1.0 0.4 224428 4948 ? Ss 15:26 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 3698 0.0 0.4 224368 4636 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3699 0.0 0.4 224368 4636 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3700 0.0 0.4 224368 4636 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3701 0.0 0.4 224368 4636 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3702 0.0 0.4 224368 4640 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3703 0.0 0.4 224368 4640 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3704 0.0 0.4 224368 4640 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3705 0.0 0.4 224368 4640 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3706 0.0 0.4 224368 4640 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3707 0.0 0.4 224368 4640 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3708 0.0 0.4 224368 4640 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3709 0.0 0.4 224368 4640 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3710 0.0 0.4 224368 4640 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3711 0.0 0.4 224368 4640 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3712 0.0 0.4 224368 4644 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3713 0.0 0.4 224368 4644 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3714 0.0 0.4 224368 4644 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3715 0.0 0.4 224368 4644 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3716 0.0 0.4 224368 4644 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3717 0.0 0.4 224368 4644 ? S 15:26 0:00 php-fpm: pool Anna.com php-fpm 3718 0.0 0.4 224368 4640 ? S 15:26 0:00 php-fpm: pool www php-fpm 3719 0.0 0.4 224368 4640 ? S 15:26 0:00 php-fpm: pool www php-fpm 3720 0.0 0.4 224368 4640 ? S 15:26 0:00 php-fpm: pool www php-fpm 3721 0.0 0.4 224368 4640 ? S 15:26 0:00 php-fpm: pool www php-fpm 3722 0.0 0.4 224368 4644 ? S 15:26 0:00 php-fpm: pool www php-fpm 3723 0.0 0.4 224368 4644 ? S 15:26 0:00 php-fpm: pool www php-fpm 3724 0.0 0.4 224368 4644 ? S 15:26 0:00 php-fpm: pool www php-fpm 3725 0.0 0.4 224368 4644 ? S 15:26 0:00 php-fpm: pool www php-fpm 3726 0.0 0.4 224368 4644 ? S 15:26 0:00 php-fpm: pool www php-fpm 3727 0.0 0.4 224368 4644 ? S 15:26 0:00 php-fpm: pool www php-fpm 3728 0.0 0.4 224368 4648 ? S 15:26 0:00 php-fpm: pool www php-fpm 3729 0.0 0.4 224368 4648 ? S 15:26 0:00 php-fpm: pool www php-fpm 3730 0.0 0.4 224368 4648 ? S 15:26 0:00 php-fpm: pool www php-fpm 3731 0.0 0.4 224368 4648 ? S 15:26 0:00 php-fpm: pool www php-fpm 3732 0.0 0.4 224368 4648 ? S 15:26 0:00 php-fpm: pool www php-fpm 3733 0.0 0.4 224368 4648 ? S 15:26 0:00 php-fpm: pool www php-fpm 3734 0.0 0.4 224368 4648 ? S 15:26 0:00 php-fpm: pool www php-fpm 3735 0.0 0.4 224368 4648 ? S 15:26 0:00 php-fpm: pool www php-fpm 3736 0.0 0.4 224368 4648 ? S 15:26 0:00 php-fpm: pool www php-fpm 3737 0.0 0.4 224368 4648 ? S 15:26 0:00 php-fpm: pool www root 3739 0.0 0.0 112664 964 pts/2 S+ 15:26 0:00 grep --color=auto php-fpm


本文标题:php-fpm的pool、 php-fpm慢执行日志、 php-fpm进程管理
分享路径:http://cdxtjz.cn/article/cjisjg.html

其他资讯