PHP-FPM of PHP Performance optimization

Source: Internet
Author: User
Tags configuration php


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.

 Make  Make Install

Second, the configuration php-fpm

Shell >CP/usr/local/src/php-5.6. -/php.ini-production/usr/local/php/PHP.ini # This is the PHP config file Shell>CP/usr/local/src/php-5.6. -/SAPI/FPM/INIT.D.PHP-FPM/ETC/INIT.D/PHP-FPM # This is php-FPM startup script Shell> cd/usr/local/php/etc/Shell>CPPhp-fpm.conf.default php-fpm.conf # Copying a copy of the configuration file Shell> Vim php-Fpm.conf[global]pid= run/php-Fpm.pid # Pidrlimit_files=65535# Open File number limit [www] # process Pool user=Nginx # Running group with Nginx identity=Nginxlisten=127.0.0.1:9000# Listen to this machine9000Port; Listen=/dev/shm/php-Cgi.sock. # listen to the UNIX socket and put the socket in the memory space, faster (Nginx to modify the corresponding)!;listen.backlog=10240# UNIX Socket is a bit unstable in the way of high concurrency, this parameter is used to alleviate (SOCKET waiting queue Length); Listen.owner=Nginx # UNIX SOCKET permissions; Listen.group=Nginx;listen.mode=0660pm=Dynamic # Creates a process, dynamically creates a Pm.max_children= +# 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 very high) Pm.start_servers=5# Initial number of processes Pm.min_spare_servers=5# Minimum number of idle processes pm.max_spare_servers=Ten# Maximum number of idle processes Pm.status_path=/php_status # php-FPM Status Monitoring (Nginx to set access permissions) Shell> 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 Access_log off directly in server {}; allow127.0.0.1; allow36.110.41.194; # do permissions deny all; Fastcgi_pass127.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 datapool:www # Process Pool name Process Manager:dynamic # Progress management mode start Time: A/jan/ .: the: the:xx+0800# Startup time start since:375# Run-time accepted Conn:7# The number of requests accepted by the current process pool Listen queue:0# Request Wait queue, if not for0, which means that the FPM process is insufficient and requires the addition of the Max Listen queue:0# Maximum number of wait queues listen queue len:1024x768# SOCKET Waiting Queue Length idle processes:4# Idle Process number Active processes:1# Active Processes Total Processes:5# total number of processes Max Active processes:1# Maximum number of active processes Max children reached:0# Number of times to reach the maximum number of processes, if not0means that the maximum number of processes is insufficient and requires an increase of 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!

PHP-FPM of PHP Performance optimization

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.