Currently, the latest 5.3.x php-fpm has two ways to manage processes: static and dynamic. if it is set to static, the number of processes is always pm from start to end. the number specified by max_children. start... currently, the latest 5.3.x php-fpm has two ways to manage processes: static and dynamic. if it is set to static, the number of processes is always pm from start to end. the number specified by max_children. start_servers, pm. min_spare_servers, pm. the max_spare_servers configuration does not work.
If it is set to dynamic, the number of processes is dynamic, starting with pm. the number specified by start_servers. if there are many requests, it will automatically increase, but it cannot exceed pm. the number of idle processes specified by max_children. min_spare_servers: if the number of processes is large, it will also be cleaned up to ensure that the number of redundant processes is no greater than that of pm. max_spare_servers.
After the php-fpm is started, a php-cgi process is about 3 m memory, but some memory cannot be released after they have processed some requests, the occupied memory can reach 20 M-30M.
For applications with a tight memory and a low concurrency, you can use static mode to control the total memory consumption of php-fpm, make the system run more smoothly. In addition, because the concurrency is small, you can set pm. max_requests to a smaller value, so that the php-fpm process can be restarted and the occupied memory can be released.
Use PHP-FPM to control FastCGI processes of PHP-CGI
/Usr/local/php/sbin/php-fpm {start | stop | quit | restart | reload | logrotate} -- start fastcgi process of php -- stop Force terminate fastcgi process of php -- quit smoothly terminates php fastcgi process -- restart restarts php fastcgi process -- reload re-smoothly loads php. ini -- logrotate re-enable log files
Php-fpm currently has two main branches, which correspond to previous versions of php-5.3.3 and later versions of php-5.3.3. In 5.2.x, the php-fpm.conf uses xml format, and in new versions later than 5.3.3, it is the same configuration style as php. ini. For versions later than 5.5.3, there are two management methods for php-fpm processes-static and dynamic. The specific/usr/local/php/conf/php-fpm.conf.default configuration is as follows:
; Choose how the process manager will control the number of child processes. ; Possible Values: ; static - a fixed number (pm.max_children) of child processes; ; dynamic - the number of child processes are set dynamically based on the ; following directives. With this process management, there will be ; always at least 1 children. ; pm.max_children - the maximum number of children that can ; be alive at the same time. ; pm.start_servers - the number of children created on startup. ; pm.min_spare_servers - the minimum number of children in 'idle' ; state (waiting to process). If the number ; of 'idle' processes is less than this ; number then some children will be created. ; pm.max_spare_servers - the maximum number of children in 'idle' ; state (waiting to process). If the number ; of 'idle' processes is greater than this ; number then some children will be killed. ; ondemand - no children are created at startup. Children will be forked when ; new requests will connect. The following parameter are used: ; pm.max_children - the maximum number of children that ; can be alive at the same time. ; pm.process_idle_timeout - The number of seconds after which ; an idle process will be killed. ; Note: This value is mandatory. pm = dynamic
As shown above, the default dynamic management mode is enabled. The number of php-fpm processes is dynamic, starting with pm. the number specified by start_servers. if there are too many requests, the number of idle processes is automatically increased to ensure that the number of idle processes is no less than pm. min_spare_servers: if the number of processes is large, it will also be cleaned up to ensure that the number of redundant processes is no greater than that of pm. max_spare_servers. In the preceding configuration file, we can see that the settings of four parameters are involved, and their functions are as follows:
Pm. max_children: Number of php-fpm processes enabled in static mode.
Pm. start_servers: number of initial php-fpm processes in Dynamic mode.
Pm. min_spare_servers: the minimum number of php-fpm processes in Dynamic mode.
Pm. max_spare_servers: maximum number of php-fpm processes in Dynamic mode.
If dm is set to static, only the pm. max_children parameter takes effect. The system will enable the set number of php-fpm processes.
If dm is set to dynamic, the pm. max_children parameter is invalid and the following three parameters take effect. The system starts pm when php-fpm starts running. start_servers php-fpm processes, and then dynamic in pm according to system requirements. min_spare_servers and pm. adjust the number of php-fpm processes between max_spare_servers.
Which execution method is better for our servers? In fact, like Apache, the running PHP program may have more or less memory leakage after execution. This is why a php-fpm process only occupies about 3 m of memory at the beginning, and will rise to 20-30 m after running for a period of time.
For a server with a large memory (such as 8 GB or above), it is more appropriate to specify a static max_children, because no additional process count control is required and the efficiency is improved. Because frequent switching of the php-fpm process also has a time delay, enabling static mode will be better if the memory is large enough. For example, if the 8 GB memory can be set to 100, the memory consumed by the php-fpm can be controlled at 2G-3G ., If the database and web application are on different servers, the machine only runs the web application, and the size can reach about 300. If the memory is slightly smaller, such as 1 GB, the specified number of static processes is more conducive to server stability. In this way, php-fpm can only obtain enough memory and allocate a small amount of memory to other applications, making the system run more smoothly.
For servers with small memory, for example, VPS with M memory, even if a 20 m memory is used, 10 php-cgi processes will consume m of memory, the system crash should be normal. Therefore, we should try our best to control the number of php-fpm processes, and specify a small static number for other applications after specifying the memory occupied by other applications, which will make the system more stable. Or use the dynamic mode, because the dynamic mode will end unnecessary processes and some memory can be recycled and released, it is recommended to use on servers or VPS with less memory. For example, we recommend that you set pm. max_spare_servers to 20 for m vps. For pm. min_spare_servers, we recommend that you set the parameter based on the server load. the value range is 5 ~ Between 10.
These two different process management methods can be adjusted according to the actual needs of the server.
The following parameters are involved: pm, pm. max_children, pm. start_servers, pm. min_spare_servers, and pm. max_spare_servers.
Pm indicates the method used. you can select either static or dynamic values ). In older versions, dynamic is called apache-like. Note the configuration file description.
The meanings of the following four parameters are:
Pm. max_children: Number of php-fpm processes enabled in static mode.
Pm. start_servers: number of initial php-fpm processes in Dynamic mode.
Pm. min_spare_servers: the minimum number of php-fpm processes in Dynamic mode.
Pm. max_spare_servers: maximum number of php-fpm processes in Dynamic mode.
If dm is set to static, only the pm. max_children parameter takes effect. The system will enable the set number of php-fpm processes.
If dm is set to dynamic, the pm. max_children parameter is invalid and the following three parameters take effect. The system starts pm when php-fpm starts running. start_servers php-fpm processes, and then dynamic in pm according to system requirements. min_spare_servers and pm. adjust the number of php-fpm processes between max_spare_servers.
Which execution method is better for our servers? In fact, like Apache, the running PHP program may have more or less memory leakage after execution. This is why a php-fpm process only occupies about 3 m of memory at the beginning, and will rise to 20-30 m after running for a period of time.
For a server with a large memory (such as 8 GB or above), it is more appropriate to specify a static max_children, because no additional process count control is required and the efficiency is improved. Because frequent switching of the php-fpm process also has a time delay, enabling static mode will be better if the memory is large enough. The quantity can also be obtained based on memory/30 M. For example, if the 8 GB memory can be set to 100, the memory consumed by the php-fpm can be controlled at 2G-3G. If the memory is slightly smaller, such as 1 GB, the specified number of static processes is more conducive to server stability. In this way, php-fpm can only obtain enough memory and allocate a small amount of memory to other applications, making the system run more smoothly.
For servers with small memory, for example, VPS with M memory, even if a 20 m memory is used, 10 php-cgi processes will consume m of memory, the system crash should be normal. Therefore, we should try to control the number of php-fpm processes as much as possible. after specifying the memory occupied by other applications, we should specify a static small number for it, this will make the system more stable, or use a dynamic mode, because the dynamic mode will end redundant processes, and some memory can be recycled and released, therefore, we recommend using servers or VPS with less memory. The maximum number is determined by memory/20 MB. For example, we recommend that you set pm. max_spare_servers to 20 for m vps. for pm. min_spare_servers, we recommend that you set it based on the server load. the appropriate value is 5 ~ Between 10.
Article address:
Reprint at will ^ please include the address of this article!