50 Lessons PHP-FPM (pool, slow execution log, Open_basedir, process Management)

Source: Internet
Author: User
Tags fpm php website

The pool of PHP-FPM

Its pool is its pool.

[[email protected] etc]# cd /usr/local/php-fpm/etc/[[email protected] etc]# lspear.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.piderror_log = /usr/local/php-fpm/var/log/php-fpm.log[www] listen = /tmp/php-fcgi.sock#listen = 127.0.0.1:9000listen.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

Set up multiple pool

* Enter/usr/local/php-fpm/etc/under Edit php-fpm.conf

[[email protected] etc]# cd /usr/local/php-fpm/etc/[[email protected] etc]# lspear.conf  php-fpm.conf  php-fpm.conf.default  php.ini[[email protected] etc]# vim php-fpm.conf

See if there are any syntax errors after adding the above

[[email protected] etc]# /usr/local/php-fpm/sbin/php-fpm -t[17-Aug-2018 11:03:39] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful

No syntax errors and then restarts

[[email protected] etc]# /etc/init.d/php-fpm reloadReload service php-fpm  done

Then use PS to see

[[email protected] etc]# ps aux |grep php-fpm

How to use a two pool

Enter the/usr/local/nginx/conf/vhost/directory to edit test.com.conf

[[email protected] etc]# cd /usr/local/nginx/conf/vhost/[[email protected] vhost]# lsaaa.com.conf  ld.conf  proxy.conf  ssl.conf  
[[email protected] vhost]# vim test.com.conf    expires 7d;    valid_referers none blocked server_names  *.test.com ;    if ($invalid_referer) {        return 403;    }    access_log off;}    location ~ .*\.(js|css)$    {#          expires      12h;          access_log off;    }    location /admin/    {      allow 192.168.63.100;      allow 127.0.0.1;      deny all;      }    location ~ .*(upload|image)/.*\.php$    {        deny all;    }    if ($http_user_agent ~* ‘Spider/3.0|YoudaoBot|Tomato‘)    {      return 403;    }    location ~ \.php$    {        include fastcgi_params;        fastcgi_pass unix:/tmp/php-fcgi.sock;      ##**这里定义成php-fcgi.sock**        #fastcgi_pass 127.0.0.1:9000;        fastcgi_index index.php;        fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;    }    access_log /tmp/test.com.log hanshuo;}

And then define another pool.

[[email protected] vhost]# lsaaa.com.conf  ld.conf  proxy.conf  ssl.conf  test.com.conf
[[email protected] vhost]# vim aaa.com.conf
[[email protected] vhost]# vim aaa.com.confserver{    listen 80 default_server;    server_name aaa.com;    index index.html index.htm index.php;    root /data/wwwroot/default;  location ~ \.php$                           ##添加这里    {        include fastcgi_params;        fastcgi_pass unix:/tmp/han.sock;                         fastcgi_index index.php;        fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;    }}

PHP also supports the Include entry php-fpm.conf edit

[[email protected] etc]# mkdir php-fpm.d     ##创建php-fpm.d因为include = etc/php-fpm.d/*.conf![[email protected] etc]# cd php-fpm.d/       ##进入[[email protected] php-fpm.d]# vim www.conf    ##编辑[www]                                    ##写入一下内容 listen = /tmp/php-fcgi.sock#listen = 127.0.0.1:9000listen.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
[[email protected] php-fpm.d]# vim han.com    ##然后在创建一个目录han.com[han.com]                       ##写入内容 listen = /tmp/han.sock#listen = 127.0.0.1:9000listen.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

See if the configuration is wrong

[[email protected] php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t[17-Aug-2018 11:44:58] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful

* Restart effect is not the same as before add = etc/php-fpm.d/. conf is the same * *

[[email protected] php-fpm.d]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . doneStarting php-fpm  done

PHP-FPM Slow Execution Log

PHP-FPM Slow execution log is very useful lamp is not, lnmp have, why analysis slow execution log, in operation and maintenance work often encounter a problem, someone often feedback site visit slow, why slow to know the root cause, slow in where, PHP website have ways to find out where he is slow, View with slow execution log

Configure PHP-FPM Slow execution log for example, for www.conf

Edit/usr/local/php-fpm/etc/php-fpm.d/under www.conf, add content

[[email protected] php-fpm.d]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf      ##加入下边的两行request_slowlog_timeout = 1slowlog = /usr/local/php-fpm/var/log/www-slow.log

Detect and Reload

[[email protected] php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t[17-Aug-2018 13:29:11] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful[[email protected] php-fpm.d]# /etc/init.d/php-fpm reloadReload service php-fpm  done

See if a log file has been generated with cat to view logs

[[email protected] php-fpm.d]# ls /usr/local/php-fpm/var/log/www-slow.log       ##已生成/usr/local/php-fpm/var/log/www-slow.log

PHP to emulate slow execution log write a script

[[email protected] php-fpm.d]# vim /data/wwwroot/test.com/sleep.php     编辑个脚本写入下边的代码<?php echo “test slow log”;sleep(2);echo “done”;?>      ##故意休眠两秒钟~                                                                                                                                                            ~                                                     

Open_basedir

Editing a configuration file

[[email protected] php-fpm.d]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf     ##加入以下配置php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/

Start

Test

Viewing the error log

To define the PHP-FPM error log.

[[email protected] php-fpm.d]# vim /usr/local/php-fpm/etc/php.ini     


12.24 PHP-FPM Process Management

50 Lessons PHP-FPM (pool, slow execution log, Open_basedir, process Management)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.