PHP-FPM is a phpfastcgi process manager and is for PHP only.
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.
PHP5.3.3 has integrated php-fpm, 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. The PHP-FPM can be turned on with the –ENABLE-FPM parameter when the./configure.
using PHP-FPM to control the fastcgi process of php-cgi
/usr/local/php/sbin/php-fpm{start|stop|quit|restart|reload|logrotate}
--start starting PHP's fastcgi process
--stop forcing the fastcgi process to terminate PHP
--quit smooth termination of PHP fastcgi process
--restart restarting PHP's fastcgi process
--reload re-load PHP php.ini
--logrotate re-enabling the log file
PHP-FPM has two modes 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 increase the number of PHP-FPM processes to the upper limit, when idle time automatically frees the number of idle processes to a lower limit.
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