Brief introduction:
PHP-FPM is a PHP FastCGI manager, General Nginx run PHP program will be thrown to the PHP program php-fpm to resolve. All right, that's it!
PHP 5.4 began to integrate the PHP-FPM, that is, when compiling PHP, as long as--ENABLE-FPM installed the PHP-FPM.
I. Installation of 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-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, which has a parameter is--ENABLE-FPM Yes, this is the Enable PHP-FPM extension.
Shell > make; Make install
Second, configure 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 &G T CP Php-fpm.conf.default php-fpm.conf # Copy a configuration file Shell > Vim php-fpm.conf [global] pid = run/php-fpm.pid # pid Rlimit_
Files = 65535 # open file limit [www] # process Pool user = Nginx # run group = Nginx Listen = 127.0.0.1:9000 # monitor Native 9000 port ; listen =/dev/shm/php-cgi.sock; # Monitor UNIX sockets, and put the socket in the memory space, faster (Nginx also want to modify)!; Listen.backlog = 10240 # UNIX socket is a bit unstable with high concurrency, which is used to mitigate (S Ocket wait queue length); Listen.owner = nginx # UNIX SOCKET permissions; listen.group = nginx; Listen.mode = 0660 pm = dynamic # How to create a process, Dynamically Create Pm.max_children = 32 # Maximum number of processes (not only to see memory to create, to see specific usage, sometimes enough memory, most processes, resulting in frequent CPU context switching, load will be very high) Pm.start_servers = 5 # Initial process number PM . min_spare_servers = 5 # Minimum number of idle processes pm.max_spare_servers = 10 # Maximum number of idle processes pm.status_path =/php_status # PHP-FPM StatusMonitoring (Nginx to set access rights) Shell > Service php-fpm Start
third, monitor php-fpm
Shell > vim/usr/local/nginx/conf/nginx.conf Location ~/php_status {# Create a separate server or add configuration access directly to server {}
_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 is the way of UNIX sockets, write 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 the path to get the following data p OOL:WWW # Processes Pool name Process Manager:dynamic # Process management mode start time:22/jan/2016:15:49:00 +0800 # start Time star T since:375 # Run-time Long accepted Conn:7 # The number of requests received by the current process pool Listen queue:0 # request waiting queues, if not 0, means F Insufficient PM process to increase Max Listen queue:0 # max wait queue number listen Queue len:1024 # SOCKET wait Queue Length idle # Number of idle processes active Processes:1 # Active process number Total Processes:5 # max Active Processes:1 # most Large active process number Max CHIldren reached:0 # reaches the maximum number of processes, if not 0, means that the maximum number of processes is insufficient, the need to increase the number of slow requests:0 # Slow request, you need to set slow log shell ;
Curl Http://127.0.0.1/php_status # Here are a number of parameters to choose from, such as http://127.0.0.1/php_status?html,? JSON,? xml,??
# I think using a Python script as a monitor, JSON format is the best!