This article introduces to you through the PHP-FPM implementation of performance optimization configuration method and considerations, the need for small partners can refer to the following
Brief introduction:
PHP-FPM is a PHP FastCGI manager, General Nginx above the PHP program will throw PHP program to PHP-FPM to parse. All right, that's it!
PHP 5.4 began to integrate the PHP-FPM, that is, when compiling PHP, as long as the--ENABLE-FPM installed PHP-FPM.
First, install the PHP-FPM
Shell >./configure--prefix=/usr/local/php \--with-config-file-path=/usr/local/php--with-mysql=/usr/local/ mysql/\--with-mysqli=/usr/local/mysql/bin/mysql_config--with-gd--with-xsl--with-bz2 \--with-zlib--with-curl-- With-pear--without-iconv--with-mcrypt \--with-gettext--with-openssl--with-libxml-dir--with-png-dir-- With-jpeg-dir--with-freetype-dir \--with-libdir=lib64--enable-ftp--enable-fpm--enable-opcache--enable-exif-- Enable-soap--enable-bcmath--enable-calendar \--enable-sockets--enable-mbstring--enable-gd-native-ttf-- Disable-rpath--disable-debug
# # See above this heap of parameters No, this is in compiling PHP, where there is a parameter is--ENABLE-FPM Yes, this is the Enable PHP-FPM extension.
Shell > make; Make install
Second, the configuration php-fpm
Shell > Cp/usr/local/src/php-5.6.17/php.ini-production/usr/local/php/php.ini # This is the PHP configuration file Shell > cp/usr/local/ SRC/PHP-5.6.17/SAPI/FPM/INIT.D.PHP-FPM/ETC/INIT.D/PHP-FPM # This is PHP-FPM's startup script Shell > Cd/usr/local/php/etc/shell > CP php-fpm.conf.default php-fpm.conf # Copy a configuration file shell > Vim php-fpm.conf[global]pid = run/php-fpm.pid # Pidrlimit_f Iles = 65535 # Open file limit [www] # process Pool user = Nginx # run as Nginx # = Nginxlisten = 127.0.0.1:9000 # Listen to the 9000 port of this machine; listen = /dev/shm/php-cgi.sock; # listen to the UNIX socket, and put the socket in the memory space, faster (Nginx also modify)!;listen.backlog = 10240 # UNIX socket is a bit unstable in the way high concurrency, this parameter is used to alleviate (so Cket wait queue length); Listen.owner = The permissions of the Nginx # UNIX SOCKET; listen.group = Nginx;listen.mode = 0660pm = dynamic # The way the process was created, the PM is created dynamically. Max_children = 32 # Maximum number of processes (can not only look at the memory to create, to see the specific usage, sometimes enough memory, the number of processes mostly, resulting in CPU frequent context switching, the load will be high) Pm.start_servers = 5 # initial process number Pm.min_spare _servers = 5 # Minimum number of idle processes pm.max_spare_servers = 10 # maximum idle Process pm.status_path =/php_status # PHP-FPM status Monitor (Nginx to set access rights) Shel L > SErvice php-fpm Start
third, monitoring php-fpm
Shell > Vim/usr/local/nginx/conf/nginx.conflocation ~/php_status {# Create a separate server or add configuration directly to the server {} Access_log Off Allow 127.0.0.1; Allow 36.110.41.194; # do permissions deny all; Fastcgi_pass 127.0.0.1:9000; # if it's a UNIX SOCKET, write something like this: Fastcgi_pass Unix:/dev/shm/php-cgi.sock; Fastcgi_param script_filename $fastcgi _script_name; Include Fastcgi_params;} Shell > Kill-hup ' cat/usr/local/nginx/logs/nginx.pid ' shell > Curl Http://127.0.0.1/php_status # Access this path to get the following data pool: WWW # process Pool name Process Manager:dynamic # processes managed by Start time:22/jan/2016:15:49:00 +0800 # startup time start since: 375 # Runtime accepted Conn:7 # Number of requests received by the current process pool Listen queue:0 # request waiting queue, if not 0, means that the FPM process is insufficient and requires Increase Max Listen queue:0 # max wait queue number listen Queue len:1024 # SOCKET Wait Queue Length idle Processes:4 # Idle Process Count Active Processes:1 # Active number of processes total Processes:5 # max active PROCESSES:1 # max active process Count Max Childr En reached:0 # achieves maximumNumber of processes, if not 0, means that the maximum number of processes is insufficient, need to increase slow requests:0 # Slow request number, need to set slow Logshell > Curl Http://127.0.0.1/php_status # There are a variety of parameters to choose from, such as: http://127.0.0.1/php_status?html, JSON,? xml,? full
# I want to use a Python script as a monitor, the JSON format is the best!
Summary: The above is the entire content of this article, I hope to be able to help you learn.