PHP-FPM to achieve performance optimization

Source: Internet
Author: User
This article describes how to configure and pay attention to performance optimization through php-fpm. if you need it, refer to the following introduction:

PHP-FPM is a PHP FastCGI manager, the general Nginx above the run PHP program will be PHP program thrown to the PHP-FPM for parsing. Okay, that's it!

PHP 5.4 began to integrate the PHP-FPM, that is, when compiling PHP, as long as -- enable-fpm is installed with the PHP-FPM.

1. install 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 the above heap parameter no, this is in the PHP compilation, one of the parameters is -- enable-fpm is correct, this is to enable the PHP-FPM extension.

shell > make; make install

2. configure PHP-FPM

Shell & gt; cp/usr/local/src/php-5.6.17/php. ini-production/usr/local/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 the PHP-FPM 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_files = 65535 # limit on the number of files opened [www] # process pool user = nginx # nginx Run group = nginxlisten = 127.0.0.1: 9000 # listen to Port 9000 of the local machine; listen =/dev/shm/php-cgi.sock; # listen to unix socket, and put the SOCKET in the memory space, faster (Nginx needs to be modified accordingly )!; Listen. backlog = 10240 # The unix socket mode is somewhat unstable in high concurrency. this parameter is used to alleviate (SOCKET waiting queue length); listen. owner = nginx # unix socket permission; listen. group = nginx; listen. mode = 0660pm = dynamic # Create a process dynamically. max_children = 32 # maximum number of processes (not just memory creation, depending on the specific usage, sometimes the memory is sufficient and the number of processes is large, leading to frequent CPU context switching and high load) pm. start_servers = 5 # Number of initial processes 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 status monitoring (Nginx needs to set access permissions) shell> service php-fpm start

3. monitoring PHP-FPM

Shell> vim/usr/local/nginx/conf/nginx. conflocation ~ /Php_status {# Create a separate server or directly add access_log off to server {}; allow 127.0.0.1; allow 36.110.41.194; # grant permissions to deny all; fastcgi_pass 127.0.0.1: 9000; # If it is unix socket method, to 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 # Obtain the following data pool when accessing this path: www # process pool name: process manager: dynamic # process management method start time: 22/Jan/2016: 15: 49: 00 + 0800 # start Time since: 375 # run time accepted conn: 7 # number of requests received by the current process pool listen queue: 0 # request waiting queue. if not 0, this means that the FPM process is insufficient. you need to increase the max listen queue: 0 # maximum number of waiting queues listen queue len: 1024 # SOCKET waiting queue length idle processes: 4 # Number of idle processes active processes: 1 # total number of active processes: 5 # total number of processes max active processes: 1 # maximum number of active processes max children reached: 0 # maximum number of processes, if the value is not 0, the maximum number of processes is insufficient. you need to increase the slow requests: 0 # Number of slow requests. you need to set slow logshell> curl http://127.0.0.1/php_status # There are multiple parameters to choose from, for example: http://127.0.0.1/php_status ? Html ,? Json ,? Xml ,? Full

# I want to use a python script for monitoring ,? Json format is the best!

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.