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

php-fpm的pool

  • 为了避免因多站点使用同一个pool时,如果一个站点访问量过大导致资源耗尽出现问题,进而影响使用同一个pool的其他站点的正常运行,就需要对每个站点配置一个单独的pool。实现方式和nginx的vhost差不多
  • 编辑主配置文件
    [[email protected] aming.com]# vim /usr/local/php-fpm/etc/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
    include = etc/php-fpm.d/*.conf
  • 重建多个pool
    [[email protected] aming.com]# mkdir /usr/local/php-fpm/etc/php-fpm.d
    [[email protected] aming.com]# cd !$
    cd /usr/local/php-fpm/etc/php-fpm.d
    [[email protected] 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
    [[email protected] php-fpm.d]# vim aming.conf
    [aming]
    listen = /tmp/aming.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
    [[email protected] php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
    [18-Jun-2018 23:31:06] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
    [[email protected] php-fpm.d]# /etc/init.d/php-fpm restart
    Gracefully shutting down php-fpm . done
    Starting php-fpm  done
  • 查看
    [[email protected] php-fpm.d]# ps aux |grep php-fpm
    root      5306  0.2  0.2 227292  4984 ?        Ss   23:31   0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
    php-fpm   5307  0.0  0.2 227232  4724 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5308  0.0  0.2 227232  4724 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5309  0.0  0.2 227232  4724 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5310  0.0  0.2 227232  4724 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5311  0.0  0.2 227232  4728 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5312  0.0  0.2 227232  4728 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5313  0.0  0.2 227232  4728 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5314  0.0  0.2 227232  4728 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5315  0.0  0.2 227232  4728 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5316  0.0  0.2 227232  4728 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5317  0.0  0.2 227232  4728 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5318  0.0  0.2 227232  4728 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5319  0.0  0.2 227232  4728 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5320  0.0  0.2 227232  4728 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5321  0.0  0.2 227232  4732 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5322  0.0  0.2 227232  4732 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5323  0.0  0.2 227232  4732 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5324  0.0  0.2 227232  4732 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5325  0.0  0.2 227232  4732 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5326  0.0  0.2 227232  4732 ?        S    23:31   0:00 php-fpm: pool aming
    php-fpm   5327  0.0  0.2 227232  4728 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5328  0.0  0.2 227232  4728 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5329  0.0  0.2 227232  4728 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5330  0.0  0.2 227232  4728 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5331  0.0  0.2 227232  4732 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5332  0.0  0.2 227232  4732 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5333  0.0  0.2 227232  4732 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5334  0.0  0.2 227232  4732 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5335  0.0  0.2 227232  4732 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5336  0.0  0.2 227232  4732 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5337  0.0  0.2 227232  4736 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5338  0.0  0.2 227232  4736 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5339  0.0  0.2 227232  4736 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5340  0.0  0.2 227232  4736 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5341  0.0  0.2 227232  4736 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5342  0.0  0.2 227232  4736 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5343  0.0  0.2 227232  4736 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5344  0.0  0.2 227232  4736 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5345  0.0  0.2 227232  4736 ?        S    23:31   0:00 php-fpm: pool www
    php-fpm   5346  0.0  0.2 227232  4736 ?        S    23:31   0:00 php-fpm: pool www
    root      5350  0.0  0.0 112680   984 pts/1    S+   23:32   0:00 grep --color=auto php-fpm

    PHP慢执行日志

  • 配置文件中加入下面两行
    [[email protected] ~]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
    request_slowlog_timeout = 1
    #当请求超过1秒开始记录日志
    slowlog = /usr/local/php-fpm/var/log/www-slow.log
    #日志存放地址
  • 测试
    [[email protected] ~]# vim /data/wwwroot/test.com/sleep.php
    <?php
    echo "test slow log";
    sleep(2);
    echo "done";
    ?>
    [[email protected] ~]# curl -x127.0.0.1:80 test.com/sleep.php
    test slow logdone
    [[email protected] ~]# cat /usr/local/php-fpm/var/log/www-slow.log
    [19-Jun-2018 08:58:20]  [pool www] pid 1451
    script_filename = /data/wwwroot/test.com/sleep.php
    [0x00007f4cadc922e0] sleep() /data/wwwroot/test.com/sleep.php:3

    open_basedir

  • 当一台服务器跑多个站点时,可以使用openbasedir限定各个站点所能访问的服务器上的目录的范围,就需要每个pool设定open basedir
    [[email protected] ~]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
    php_admin_value[open_basedir]=/data/wwwroot/eetest.com:/tmp/
    #故意写错/data/wwwroot/eetest.com,正确是/data/wwwroot/test.com
  • 进行测试
    [[email protected] ~]# curl -x127.0.0.1:80 test.com/sleep.php -I
    HTTP/1.1 404 Not Found
    Server: nginx/1.14.0
    Date: Tue, 19 Jun 2018 01:21:13 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    X-Powered-By: PHP/5.6.30
  • 再次更改www.conf,修改路径,再次测试
    [[email protected] ~]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
    [[email protected] ~]# /etc/init.d/php-fpm restart
    Gracefully shutting down php-fpm . done
    Starting php-fpm  done
    [[email protected] ~]# curl -x127.0.0.1:80 test.com/sleep.php
    test slow logdone
  • 配置错误日志
    [[email protected] ~]# vim /usr/local/php-fpm/etc/php.ini
    error_reporting = E_ALL
    display_errors = Off
    ;error_log = syslog
    error_log = /usr/local/php-fpm/var/log/php_errors.log
    [[email protected] ~]# touch /usr/local/php-fpm/var/log/php_errors.log
    [[email protected] ~]# chmod 777 /usr/local/php-fpm/var/log/php_errors.log
    [[email protected] ~]# /etc/init.d/php-fpm restart
    Gracefully shutting down php-fpm . done
    Starting php-fpm  done
  • 再次测试,测试前故意改错
    [[email protected] ~]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
    php_admin_value[open_basedir]=/data/wwwroot/eetest.com:/tmp/
    #故意写错/data/wwwroot/eetest.com,正确是/data/wwwroot/test.com
    [[email protected] ~]# curl -x127.0.0.1:80 test.com/sleep.php -I
    HTTP/1.1 404 Not Found
    Server: nginx/1.14.0
    Date: Tue, 19 Jun 2018 01:34:14 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    X-Powered-By: PHP/5.6.30
  • 查看日志
    [[email protected] ~]# cat /usr/local/php-fpm/var/log/php_errors.log
    [19-Jun-2018 01:32:53 UTC] PHP Deprecated:  Comments starting with ‘#‘ are deprecated in Unknown on line 1 in Unknown on line 0
    [19-Jun-2018 01:32:53 UTC] PHP Deprecated:  Comments starting with ‘#‘ are deprecated in Unknown on line 1 in Unknown on line 0
    [19-Jun-2018 01:34:14 UTC] PHP Warning:  Unknown: open_basedir restriction in effect. File(/data/wwwroot/test.com/sleep.php) is not within the allowed path(s): (/data/wwwroot/eetest.com:/tmp/) in Unknown on line 0
    [19-Jun-2018 01:34:14 UTC] PHP Warning:  Unknown: failed to open stream: Operation not permitted in Unknown on line 0

    php-fpm进程管理

    [[email protected] ~]# cat /usr/local/php-fpm/etc/php-fpm.d/www.conf
    [www]
    listen = /tmp/www.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/wwwroot/test.com:/tmp/
  • pm = dynamic //动态进程管理,也可以是static,这时下面的配置不生效启动就生成50个子进程不会改变
  • 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的子进程最多可以处理这么多请求,当达到这个数值时,它会自动退出

原文地址:http://blog.51cto.com/akui2521/2130452

时间: 2024-09-29 13:01:27

php-fpm的pool、PHP慢执行日志、open_basedir、php-fpm进程管理的相关文章

51.php-fpm的pool、php-fpm慢执行日志open_basedir、php-fpm进程

一.php-fpm的pool vim /usr/local/php-fpm/etc/php-fpm.conf //在[global]部分增加 include = etc/php-fpm.d/*.conf //类似nginx的vhost mkdir /usr/local/php-fpm/etc/php-fpm.d/ cd /usr/local/php-fpm/etc/php-fpm.d/ vim www.conf //内容如下 [www] listen = /tmp/php-fcgi.sock l

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

php-fpm的pool 方法1:在大的配置文件里吗统一实现编辑配置文件重新加载配置 方法2:总分的方法,先在大的配置文件里设置一个大的目录,再在这个目录里面增加2个pool1.编辑大的配置文件2.在这个目录里面配置2个小的配置文件重新加载配置,验证pool池 php-fpm慢执行日志 配置文件重新加载 vim /data/wwwroot/test.com/sleep.php//写入如下内容测试访问效果,2秒后才出现结果查看日志结果 php-fpm定义open_basedir 编辑配置文件测试访

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

php-fpm的pool 为了避免因多站点使用同一个pool时因一个站点故障导致pool出问题,进而影响使用同一个pool的其他站点的正常运行,要对每个站点配置一个单独的pool. 为php-fpm增加pool 编辑php-fpm配置文件:......[huang.com]listen = /tmp/huang.socklisten.mode = 666user = php-fpmgroup = php-fpmpm = dynamicpm.max_children = 50pm.start_se

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

一. php-fpm的pool vim /usr/local/php/etc/php-fpm.conf//在[global]部分增加include = etc/php-fpm.d/*.confmkdir /usr/local/php/etc/php-fpm.d/cd /usr/local/php/etc/php-fpm.d vim www.conf //内容如下[www]listen = /tmp/www.socklisten.mode=666user = php-fpmgroup = php-

LNMP(php-fpm的pool,慢执行日志,定义open_bashdir,php-fpm进程管理

一.php-fpm的pool(连接池) 我们查看php的进程时,会发现,在最后一个pool的选项,而这个就是我们在php-fpm配置文件里写的一个连接池. [[email protected] ~]# ps aux | grep php-fpm root      2158  0.0  0.4 227148  4952 ?        Ss   15:57   0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)

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

                 php-fpm的pool (在之前实验中我之定义了一个pool  /usr/loacl/php-fpm/etc/php-fpm.conf ) Nginx中可以定义多个虚拟主机,也可以定义多个pool,每个pool可以监听一个端口,也可以监听一个socket. 因此在Nginx中如果有多个站点,则每个站点可以使用一个pool,这样就可以避免单独的一个站点耗尽php资源导致其他站点也访问有误. 定义多个pool: cd /usr/local/php-fpm/etc/

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

php-fpm配置 和lamp不同的是,在lnmp的架构中,php-fpm作为一个独立的服务存在,既然是独立的服务存在,那他就有自己的配置文件.php-fpm的配置文件是/usr/local/php-fpm/etc/. php-fpm的pool(池子) nginx支持多个虚拟主机,php-fmp同样也支持配置多个pool,每一个pool可以监听一个端口,也可以监听一个socket(套接口).比如我们的nginx有多个站点,那么每一个站点都可以使用一个pool.这样做的好处是当其中一个php显示5

Linux centosVMware LAMP php-fpm的pool、php-fpm慢执行日志、open_basedir、php-fpm进程管理

一.php-fpm的pool vim /usr/local/php/etc/php-fpm.conf//在[global]部分增加 include = etc/php-fpm.d/*.conf mkdir /usr/local/php/etc/php-fpm.d/ cd /usr/local/php/etc/php-fpm.d/ vim www.conf //内容如下 [www] listen = /tmp/www.sock listen.mode=666 user = php-fpm grou

50次课 php-fpm的(pool、慢执行日志、open_basedir、进程管理)

php-fpm的pool 它的pool就是它的池子 [[email protected] etc]# cd /usr/local/php-fpm/etc/ [[email protected] etc]# ls pear.conf php-fpm.conf php-fpm.conf.default php.ini [[email protected] etc]# cat php-fpm.conf [global] pid = /usr/local/php-fpm/var/run/php-fpm.