PHP-FPM pool, php slow execution log, Open_basedir, PHP-FPM process Management

Source: Internet
Author: User
Tags fpm

12.21 PHP-FPM's Pool

To avoid the pool problem caused by one site failure due to multiple sites using the same pool, and to affect the normal operation of other sites using the same pool, configure a separate pool for each site.

Add Pool to PHP-FPM

To edit the PHP-FPM configuration file:

[Email protected] etc]# vim/usr/local/php-fpm/etc/php-fpm.conf
......
[Adai.com]
Listen =/tmp/adai.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

Syntax Detection:
[Email protected] etc]#/usr/local/php-fpm/sbin/php-fpm-t
[16-aug-2017 16:10:23] Notice:configuration file/usr/local/php-fpm/etc/php-fpm.conf Test is successful

Reload the configuration file:
[Email protected] etc]#/ETC/INIT.D/PHP-FPM Reload
Reload Service PHP-FPM Done
To view a process:

[[Email protected] etc]# PS aux |grep php-fpm

PHP-FPM 6222 0.0 0.4 226640 4716? S 16:10 0:00 Php-fpm:pool www
PHP-FPM 6223 0.0 0.4 226640 4712? S 16:10 0:00 Php-fpm:pool adai.com
Configure a pool for a site

[Email protected] vhost]# vim/usr/local/nginx/conf/vhost/aaa.com.conf

Location ~. php$
{
Include Fastcgi_params;
Fastcgi_pass Unix:/tmp/adai.sock;
Fastcgi_index index.php;
Fastcgi_param Script_filename/data/wwwroot/default$fastcgi_script_name;
}
Description: Change the Fastcgi_pass address to the same address as in php-fpm.conf.

To add a php-fpm.conf child configuration file

For ease of administration, each pool in the PHP-FPM can be managed separately. Do the following to add the PHP-FPM sub-configuration file:

[Email protected] vhost]# 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
Description: Add the parameter "include = etc/php-fpm.d/. conf" In the Global variables section
. You can then clear the other parameters in the PHP-FPM configuration file and set them separately under the PHP-FPM.D directory.

[Email protected] vhost]# cd/usr/local/php-fpm/etc/

To create the specified directory:
[Email protected] etc]# mkdir PHP-FPM.D

[Email protected] etc]# CD php-fpm.d/

To create a PHP-FPM child configuration file:
[Email protected] php-fpm.d]# vim 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

[Email protected] php-fpm.d]# vim adai.conf
[Adai.com]
Listen =/tmp/adai.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

Check for syntax errors, reload:
[Email protected] php-fpm.d]#/usr/local/php-fpm/sbin/php-fpm-t
[16-aug-2017 16:49:17] Notice:configuration file/usr/local/php-fpm/etc/php-fpm.conf Test is successful

[Email protected] php-fpm.d]#/ETC/INIT.D/PHP-FPM Reload
Reload Service PHP-FPM Done
Use PS to view PHP-FPM process information after configuration is complete.

Slow execution log for 12.22 php-fpm

To turn on slow execution logging:

[Email protected] php-fpm.d]# 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] php-fpm.d]#/usr/local/php-fpm/sbin/php-fpm-t
[Email protected] php-fpm.d]#/ETC/INIT.D/PHP-FPM Reload
Test

To add a file to a site that uses the WWW pool:

Create a. php file:
[Email protected] php-fpm.d]# vim/data/wwwroot/test.com/sleep.php
<?php
echo "Test slow Log";
Sleep (2);
echo "Done";
?>
Detection:

[Email protected] php-fpm.d]# curl-x127.0.0.1:80 test.com/sleep.php
Test Slow Logdone
To view slow logs:

[Email protected] php-fpm.d]# Tail/usr/local/php-fpm/var/log/www-slow.log

[16-aug-2017 17:14:55] [Pool www] pid 6451
Script_filename =/data/wwwroot/test.com/sleep.php
[0x00007fe02560e2e0] Sleep ()/data/wwwroot/test.com/sleep.php:3
12.23 specified in php-fpm open_basedir

When a server runs multiple sites, use the openBasedir to limit the range of directories on the servers that each site can access. In the PHP-FPM service, open Basedir can be set for each pool .

Core Configuration parameters:

[Email protected] ~]# vim/usr/local/php-fpm/etc/php-fpm.d/www.conf
......
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
To create a test PHP script:

[Email protected] php-fpm.d]# vim/data/wwwroot/test.com/1.php
<?php
echo "This is a test php of Open_basedir";
Test:

[Email protected] php-fpm.d]# curl-x127.0.0.1:80 test.com/1.php
This is a test php of Open_basedir
12.24 PHP-FPM Process Management

PHP-FPM in the pool configuration parameter resolution:

[Email protected] php-fpm.d]# vim www.conf
[WWW]
Listen =/tmp/php-fcgi.sock
Listen.mode = 666
user = PHP-FPM
Group = PHP-FPM
PM = dynamic
; Defines how the process is started (dynamic, static)
; The following configuration will only take effect if this is set to dynamic
Pm.max_children = 50
; Maximum number of child processes that can be started
Pm.start_servers = 20
; Sets the number of processes that are initially started
Pm.min_spare_servers = 5
; indicates that PHP-FPM must have at least a few sub-processes when idle
Pm.max_spare_servers = 35
Indicates that PHP-FPM is idle for up to a few child processes
Pm.max_requests = 500
; Indicates the maximum number of requests a child process can accept
Rlimit_files = 1024
; Indicates how many file handles each child process has opened
Request_slowlog_timeout = 1
When the request starts logging in more than 1 seconds
Slowlog =/usr/local/php-fpm/var/log/www-slow.log
; Log storage Address
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/

PHP-FPM pool, php slow execution log, Open_basedir, PHP-FPM 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.