PHPFASTCGI Process Manager php-fpm detailed

Source: Internet
Author: User
Tags fpm php source code vps

The

PHP-FPM is a phpfastcgi process manager and is for PHP only. The
      php-fpm is actually a patch of PHP source code designed to integrate FASTCGI process management into a PHP package. It must be patch into your PHP source code and can be used after compiling and installing PHP.
       Now we can download in the latest PHP 5.3.2 source tree to directly integrate the PHP-FPM branch, it is said that the next version will be fused into the main branch of PHP. Relative SPAWN-FCGI,PHP-FPM in the CPU and memory control are better, and the former is easy to crash, must be monitored with crontab, and PHP-FPM does not have this annoyance. The
      php5.3.3 has been integrated with PHP-FPM and is no longer a third-party package. PHP-FPM provides a better way to manage the PHP process, can effectively control memory and process, can be smooth overloaded PHP configuration, more than spawn-fcgi has more advantages, so by the official PHP included.              in./configure with – The ENABLE-FPM parameter opens the PHP-FPM.
       use PHP-FPM to control the fastcgi process of php-cgi
/usr/local/php/sbin/php-fpm{start| Stop|quit|restart|reload|logrotate}
--start start php fastcgi process
--stop Force termination of PHP fastcgi process
--quit Smooth termination of PHP fastcgi process
--restart restart PHP fastcgi process
--reload re-smooth load php php.ini
--logrotate re-enable log file

PHP-FPM There are two ways of execution, like Apache, his number of processes can be divided into dynamic and static according to the settings, one is to open a specified number of PHP-FPM processes, no longer increase or decrease, the other is to start a certain number of php-fpm process, When the request is large, dynamically increases the number of PHP-FPM processes to the upper limit and automatically frees the idle process to a lower limit when idle.

These two different execution modes can be adjusted according to the actual needs of the server.

Let's talk about some of these parameters, they are pm,pm.max_children,pm.start_servers,pm.min_spare_servers and pm.max_spare_servers.

pm means that there are two values that can be selected, either static or dynamic, in that way. In older versions, dynamic is called Apache-like. This should pay attention to the instructions given in the configuration file.

The meanings of the following 4 parameters are:

Pm.max_children: The number of PHP-FPM processes that are open in static mode.
Pm.start_servers: The number of start PHP-FPM processes under dynamic mode.
Pm.min_spare_servers: The minimum number of PHP-FPM processes under dynamic mode.
Pm.max_spare_servers: The maximum number of PHP-FPM processes under dynamic mode.

If the DM is set to static, then only the Pm.max_children parameter takes effect. The system turns on several PHP-FPM processes that are set up.

If the DM is set to dynamic, then the Pm.max_children parameter is invalidated and the next 3 parameters take effect. The system starts the Pm.start_servers PHP-FPM process at the beginning of the PHP-FPM run and then dynamically pm.min_spare_servers and Pm.max_spare_ according to the system's requirements Adjusts the number of PHP-FPM processes between servers.

So, for our server, which method of execution is better? In fact, like Apache, we run a PHP program after the completion of execution, more or less there is a memory leak problem. This is why the beginning of a PHP-FPM process only consumes about 3M of memory, running for a period of time will rise to 20-30m reason. Therefore, the dynamic mode because it will end the redundant process, can be reclaimed to release some memory, so it is recommended to use on the server or VPS with less memory. The specific maximum number is based on the memory/20m. For example, 512M VPS, recommended pm.max_spare_servers set to 20. As for Pm.min_spare_servers, it is recommended to set the load on the server and compare the appropriate values between 5~10.

Then, for servers that are larger in memory, it is more efficient to set to static. Because the frequent switch PHP-FPM process will also sometimes lag, so the memory is large enough to open the static effect will be better. The quantity can also be obtained according to the memory/30m. For example, 2GB memory server, can be set to 50;4GB memory can be set to 100 and so on.

The demo parameters are as follows:

Pm=dynamic
Pm.max_children=20
Pm.start_servers=5
Pm.min_spare_servers=5
Pm.max_spare_servers=20

This allows for maximum memory savings and increased execution efficiency.

PHPFASTCGI Process Manager php-fpm detailed

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.