php-fpm的pool
•vim /usr/local/php-fpm/etc/php-fpm.conf //在[global]部分增加include并删除我们之前www池子
• include = etc/php-fpm.d/*.conf
• mkdir /usr/local/php-fpm/etc/php-fpm.d/
• cd /usr/local/php-fpm/etc/php-fpm.d/
• vim www.conf //内容如下
[www]listen = /tmp/www.socklisten.mode=666user = php-fpmgroup = php-fpmpm = dynamicpm.max_children = 50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 500rlimit_files = 1024
vim cc.conf //内容入下
[cc.com]listen = /tmp/cc.socklisten.mode=666user = php-fpmgroup = php-fpmpm = dynamicpm.max_children = 50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 500rlimit_files = 1024
•/usr/local/php-fpm/sbin/php-fpm –t
• /etc/init.d/php-fpm restart
[root@cc-01 php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t[17-Aug-2018 16:21:07] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful[root@cc-01 php-fpm.d]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . doneStarting php-fpm done
检测:
ps aux|grep php-fpm
这样多个池子就建立好了,如果我们需要多个池子就可以这样去建立!
php-fpm慢执行日志
•vim /usr/local/php-fpm/etc/php-fpm.d/www.conf//加入如下内容
request_slowlog_timeout = 1slowlog = /usr/local/php-fpm/var/log/www-slow.log
• 重新加载nginx服务
/usr/local/php-fpm/sbin/php-fpm -t
/etc/init.d/php-fpm reload• vim /data/wwwroot/test.com/sleep.php//写入如下内容
• curl -x127.0.0.1:80 test.com/sleep.php
• cat /usr/local/php-fpm/var/log/www-slow.log //日志会告诉我们哪里有问题
php-fpm定义open_basedir
•vim /usr/local/php-fpm/etc/php-fpm.d/www.conf //加入如下内容
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
测试:
[root@cc-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -IHTTP/1.1 200 OKServer: nginx/1.12.1Date: Fri, 17 Aug 2018 09:24:42 GMTContent-Type: text/html; charset=UTF-8Connection: keep-aliveX-Powered-By: PHP/5.6.32
配置错误日志
•vim /usr/local/php-fpm/etc/php.ini
display_errors = Offerror_reporting = E_ALLerror_log = /usr/local/php-fpm/var/log/php_errors.log
创建错误日志并更改权限
touch /usr/local/php-fpm/var/log/php_errors.log
chmod 777 /usr/local/php-fpm/var/log/php_errors.log•再次更改www.conf,修改路径,再次测试
php_admin_value[open_basedir]=/data/wwwroot/stest.com:/tmp/
[root@cc-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/3.phpNo input file specified.[root@cc-01 php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -IHTTP/1.1 404 Not FoundServer: nginx/1.12.1Date: Fri, 17 Aug 2018 09:32:56 GMTContent-Type: text/html; charset=UTF-8Connection: keep-aliveX-Powered-By: PHP/5.6.32
cat /usr/local/php-fpm/var/log/php_errors.log //查看错误日志
这里就能看到哪里出问题了!
php-fpm进程管理
pm = dynamic //动态进程管理,也可以是static pm.max_children = 50 //最大子进程数,ps aux可以查看 pm.start_servers = 20 //启动服务时会启动的进程数 pm.min_spare_servers = 5 //定义在空闲时段,子进程数的最少数量,如果达到这个数值时,php-fpm服务会自动派生新的子进程。 pm.max_spare_servers = 35 //定义在空闲时段,子进程数的最大值,如果高于这个数值就开始清理空闲的子进程。 pm.max_requests = 500 //定义一个子进程最多处理的请求数,也就是说在一个php-fpm的子进程最多可以处理这么多请求,当达到这个数值时,它会自动退出。
再次测试