标签:pool 慢执行日志 open_basedir php日志 进程管理
php-fpm的poolvim /usr/local/php-fpm/etc/php-fpm.conf
增加
include = etc/php-fpm.d/*.conf
删除
[www]
listen = /tmp/php-fcgi.sock
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
mkdir /usr/local/php-fpm/etc/php-fpm.d/
cd /usr/local/php-fpm/etc/php-fpm.d/
vim www.conf
增加
listen = /tmp/php-fcgi.sock
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
vim shu32.conf
增加
[shu32]
listen = /tmp/shu32.sock
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
vim /usr/local/nginx/conf/vhost/test.com.conf
##解析php##
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
}
vim /usr/local/nginx/conf/vhost/aaa.com.conf
##解析php##
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/shu32.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;
}
php-fpm与nginx都要检测生效
/usr/local/php-fpm/sbin/php-fpm -t
/etc/init.d/php-fpm reload
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
aaa与test分别使用www与shu32
ps aux |grep php-fpm
root 2001 0.0 0.4 227292 4988 ? Ss 00:16 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 2002 0.0 0.4 227232 4724 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2003 0.0 0.4 227232 4724 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2004 0.0 0.4 227232 4724 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2005 0.0 0.4 227232 4724 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2006 0.0 0.4 227232 4728 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2007 0.0 0.4 227232 4728 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2008 0.0 0.4 227232 4728 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2009 0.0 0.4 227232 4728 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2010 0.0 0.4 227232 4728 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2011 0.0 0.4 227232 4728 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2012 0.0 0.4 227232 4728 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2013 0.0 0.5 227232 5780 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2014 0.0 0.4 227232 4728 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2015 0.0 0.4 227232 4728 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2016 0.0 0.4 227232 4728 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2017 0.0 0.4 227232 4732 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2018 0.0 0.4 227232 4732 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2019 0.0 0.4 227232 4732 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2020 0.0 0.4 227232 4732 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2021 0.0 0.4 227232 4732 ? S 00:16 0:00 php-fpm: pool shu32
php-fpm 2022 0.0 0.4 227232 4728 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2023 0.0 0.4 227232 4728 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2024 0.0 0.5 227232 5508 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2025 0.0 0.5 227232 5736 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2026 0.0 0.4 227232 4732 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2027 0.0 0.4 227232 4732 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2028 0.0 0.4 227232 4732 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2029 0.0 0.4 227232 4732 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2030 0.0 0.4 227232 4732 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2031 0.0 0.4 227232 4732 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2032 0.0 0.4 227232 4732 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2033 0.0 0.4 227232 4736 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2034 0.0 0.4 227232 4736 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2035 0.0 0.4 227232 4736 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2036 0.0 0.4 227232 4736 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2037 0.0 0.4 227232 4736 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2038 0.0 0.4 227232 4736 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2039 0.0 0.4 227232 4736 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2040 0.0 0.4 227232 4736 ? S 00:16 0:00 php-fpm: pool www
php-fpm 2041 0.0 0.4 227232 4736 ? S 00:16 0:00 php-fpm: pool www
vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
增加
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
/usr/local/php-fpm/sbin/php-fpm -t
/etc/init.d/php-fpm reload
让web停顿两秒时间
vim /data/wwwroot/test.com/sleep.php
<?php
echo "test slow log";
sleep(2);
echo "done";
?>
curl -x127.0.0.1:80 test.com/sleep.php
访问有两秒时间才结束
提示访问test.com/sleep.php慢的原因在代码第三行
cat /usr/local/php-fpm/var/log/www-slow.log
[20-Mar-2018 00:57:28] [pool www] pid 2469
script_filename = /data/wwwroot/test.com/sleep.php
[0x00007fb91fc38298] sleep() /data/wwwroot/test.com/sleep.php:3
open_basedir 的作用是限制php在指定的目录里活动。
vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
添加如下代码
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
/usr/local/php-fpm/sbin/php-fpm -t
/etc/init.d/php-fpm reload
成功200
curl -x127.0.0.1:80 test.com/admin.php -I
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Mon, 19 Mar 2018 17:24:44 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30
将test.com改为wwtest.com
vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
php_admin_value[open_basedir]=/data/wwwroot/wwtest.com:/tmp/
/usr/local/php-fpm/sbin/php-fpm -t
/etc/init.d/php-fpm reload
curl -x127.0.0.1:80 test.com/admin.php -I
HTTP/1.1 404 Not Found
Server: nginx/1.12.2
Date: Mon, 19 Mar 2018 17:18:53 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30
vim /usr/local/php-fpm/etc/php.ini
log_errors = On //开启错误日志记录
error_log = /usr/local/php-fpm/var/log/php_errors.log //指定错误日志目录
error_reporting = E_ALL //设置错误级别
touch /usr/local/php-fpm/var/log/php_errors.log
chmod 777 /usr/local/php-fpm/var/log/php_errors.log
/usr/local/php-fpm/sbin/php-fpm -t
/etc/init.d/php-fpm reload
cat /usr/local/php-fpm/var/log/php_errors.log
cat /usr/local/php-fpm/etc/php-fpm.d/www.conf
[www]
listen = /tmp/php-fcgi.sock
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/wwwroot/wtest.com:/tmp/
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的子进程最多可以处理这么多请求,当达到这个数值时,它会自动退出。
php-fpm的pool、网站慢执行日志、定义open_basedir、设置php日志、进程管理
标签:pool 慢执行日志 open_basedir php日志 进程管理
原文地址:http://blog.51cto.com/shuzonglu/2088815