PHP-FPM optimization of php5.6

Source: Internet
Author: User
Tags fpm reserved

PHP-FPM optimization of php5.6



One. PHP-FPM three modes of operation OnDemand static dynamic http://blog.csdn.net/pzqingchong/article/details/53379772


Two. The dialectical view about PHP parameter optimization
https://www.douban.com/note/315222037/
Http://www.myhack58.com/Article/sort099/sort0102/2012/33364.htm




Three. PHP-FPM optimization


1.PHP-FPM configuration file

/USR/LOCAL/PHP/ETC/PHP-FPM.CONF Management PHP-FPM Service configuration file
/usr/local/php/etc/php-fpm.ini PHP Global configuration file

[Root@xclinux vhosts]# PS aux |grep php-fpm
Root 891 0.0 0.4 29156 2928? Ss 19:47 0:00 php-fpm:master process (/usr/local/php/etc/php-fpm.conf)
PHP-FPM 892 0.0 0.9 30752 6560? S 19:47 0:00 Php-fpm:pool www
PHP-FPM 893 0.0 0.9 30752 6556? S 19:47 0:00 Php-fpm:pool www
Root 1805 0.0 0.6 12332 4204 pts/0 T 22:34 0:00 vim/usr/local/php/etc/php-fpm.conf
Root 1830 0.0 0.1 5980 744 pts/0 s+ 22:36 0:00 grep php-fpm

[Root@xclinux vhosts]# vim/usr/local/php/etc/php-fpm.conf


[Root@xclinux etc]# > php-fpm.conf Empty configuration file

Root@xclinux vhosts]# vim/usr/local/php/etc/php-fpm.conf can set up multiple pool
[Global]; Pool Pools
PID =/usr/local/php/var/run/php-fpm.pid
Error_log =/usr/local/php/var/log/php-fpm.log
[WWW]
Listen =/tmp/www.sock, sock or ip+ port number for listening
user = PHP-FPM
Group = PHP-FPM
PM = dynamic, active use of static PM configuration does not take effect
Pm.max_children = 50, child process up to 50
Pm.start_servers = 20; Boot up 20 sub processes
Pm.min_spare_servers = 5, at least 5 processes are reserved when idle
Pm.max_spare_servers = 35, free up to 35 processes
pm.max_requests = 500 processing 500 requests for automatic destruction within a child process lifecycle
Rlimit_files = 1024; Each process uses the restriction of using a file descriptor


[WWW1]
Listen =/tmp/www1.sock
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


Note: note used;


Description
A. The [Global] section is a global configuration that specifies the PID file and error log path specified by the service
b. [www] is a pool (pool) www is the names of the pools, and if there are multiple pools, copy the contents and paste them in the following, depending on the name of the pool and the path of the Listen
C. Listen listener sock or ip+ port number.
Listening to the sock file, where this file needs to correspond to the file name specified in the Nginx's virtual host, multiple sites preferably multiple pool using a different sock file, and pool name
D. User name for Admin Service
E. Group Management Service user groups
F. PM Pool mode: Dynamic and static, dynamics is dynamic, if statically static, then the lower pm.start_servers = 20 effective, the other PM configuration options are not effective
G. Pm.max_children indicates how many child processes the PHP-FPM can start
H. Pm.start_servers the number of processes that start when a service is opened
I. Pm.min_spare_servers indicates that the minimum number of child processes is retained when the PHP-FPM is idle and is created automatically if the process is not sufficient at idle time.
J. Pm.max_spare_servers indicates that the maximum number of child processes is reserved when the PHP-FPM is idle, and is automatically destroyed if the process exceeds at idle time.
K. Pm.max_requests indicates how many requests can be granted by a subprocess, and if set to 500, a subprocess will be automatically destroyed after receiving 500.
L. rlimit_files Each process uses restrictions that use file descriptors, representing the number of files that each process can access. The value of this tag must be associated with the number of open files for the Linux kernel, for example, to set this value to 65535, you must perform ' ULIMIT-HSN 65536 ' on the Linux command line. (Ulimit–n can view corresponding values)


Extensions: If your site has a slow access time, we can add the following two lines to the corresponding pool:


Slowlog =/tmp/www.slow.log
Request_slowlog_timeout = 1
The above two lines mean that the time of the visit will be the execution of the script more than 1 seconds to record the script, so that we can find out whether the problem is a script or where the issue, where the timing could be adjusted


If we want to limit the access directory of the users who use this pool, we can join the following line:


Php_admin_value open_basedir=/data/www/:/tmp/
The different directories above are separated by colons: colon




Extensions: If your site has a slow access time, we can add the following two lines to the corresponding pool:


Slowlog =/tmp/www.slow.log
Request_slowlog_timeout = 1
The above two lines mean that the time of the visit will be the execution of the script more than 1 seconds to record the script, so that we can find out whether the problem is a script or where the issue, where the timing could be adjusted


If we want to limit the access directory of the users who use this pool, we can join the following line:


Php_admin_value open_basedir=/data/www/:/tmp/
The different directories above are separated by colons: colon


[Root@xclinux ~]#/usr/local/php/sbin/php-fpm-t
[12-jun-2016 01:21:38] Notice:configuration file/usr/local/php/etc/php-fpm.conf Test is successful
[Root@xclinux ~]#/etc/init.d/php-fpm start
Starting php-fpm Done


At this point, PS aux|grep PHP-FPM can see multiple pool processes www and WWW1


Benefits: Different domain names corresponding to different pool pools, can be divided into separate permissions.
The WWW1 pool operation is not affected when the WWW pool fails. A website done, other sites will not be done.


[Root@xclinux etc]# cd/usr/local/nginx/conf/vhosts/
You have new mail in/var/spool/mail/root
[Root@xclinux vhosts]# ls
111.conf default.conf Default.conf1.bak
[Root@xclinux vhosts]# Vim 111.conf
Server
{
Listen 80;
server_name www.111.com;
Index index.html index.htm index.php;
root/data/www;


Location ~ \.php$ {
Include Fastcgi_params;
Fastcgi_pass Unix:/tmp/www.sock;
#fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename/data/www$fastcgi_script_name;


}


}

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.