PHP-FPM to achieve performance optimization, php-fpm Performance Optimization

Source: Internet
Author: User
Tags php error

PHP-FPM to achieve performance optimization, php-fpm Performance Optimization

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 # access this The following data pool is obtained in the path: www # 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 re Ached: 0 # The number of times the maximum number of processes has been reached. If it is not 0, it means that the maximum number of processes is insufficient. You need to increase the number of slow requests: 0 # slow requests, you need to set slow logshell> curl http: // 127.0.0.1/php_status # There are multiple parameters to choose from, such as: 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!

Articles you may be interested in:
  • Php-fpm-based configuration details
  • Php configuration of php-fpm startup parameters and configuration details
  • How to disable php-fpm in linux
  • Nginx call php-fpm error solution and nginx configuration details
  • How to configure logging PHP error logs when using PHP-FPM in Nginx
  • Start, restart, stop scripts for Nginx and PHP-FPM
  • Installation and configuration of PHP-FPM in Linux

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.