Web server PHP-FPM File analysis

Source: Internet
Author: User
Tags vps

PHP-FPM currently has two branches, which correspond to the php-5.2.x version and the php-5.3.x version. In the 5.2.x version, php-fpm.conf uses XML format, and in the new 5.3.x version, it is the same configuration style as php.ini.


1.PHP-FPM provides a slow execution log that can dump the calling process of a slow script into the log.
PHP 5.3.3 is set up as follows:

<value name= "Request_slowlog_timeout" >5s</value><value name= "Slowlog" >logs/php-fpm-slowlog.log </value>

After PHP 5.3.3, set the following as follows:

Request_slowlog_timeout = 5sslowlog =/usr/local/php/log/php-fpm-slowlog.log

2. It is also possible to terminate a process that takes too long to execute, request_terminate_timeout
The parameter represents a wait of 10 seconds to end those PHP scripts that do not end automatically to free up the resources that are consumed.

PHP 5.3.3 Previous version:

<value name= "Request_terminate_timeout" >10s</value>

PHP 5.3.3+:

Request_terminate_timeout = 10s

3.PHP-FPM two kinds of process management methods

PM means that the use of that method is static (static) or dynamic. In older versions, dynamic is called Apache-like.

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 pm.max_children this parameter, the system will open the set number of PHP-FPM process.

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, the running PHP program will have more or less memory leaks after the execution is completed. 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.

For memory-heavy servers (such as 8G or more), it is actually more appropriate to specify a static Max_children because it does not require additional process number control to increase efficiency.

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 amount can also be based on memory/30m, such as 8GB memory can be set to 100, then PHP-FPM memory can control the appearance of 2g-3g. If the memory is slightly smaller, such as 1G, then specifying the number of static processes is more advantageous to the stability of the server. This ensures that the PHP-FPM only gets enough memory and allocates a limited amount of memory to other applications, which makes the system run more smoothly.

For small memory servers, such as 256M of memory VPs, even according to a 20M of memory to calculate, 10 php-cgi process will consume 200M of memory, the system crash should be very normal.

Therefore, the number of PHP-FPM processes should be controlled as much as possible, and when the memory used by other applications is generally clear, assigning a small amount of static to it will make the system more stable. Or use dynamic mode, because the dynamic way will end off the redundant process, can reclaim 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.


Reference:

Http://www.linuxde.net/2011/12/3254.html

Http://www.linuxde.net/2013/02/12101.html

This article is from the "Fightering-cluter" blog, make sure to keep this source http://3974020.blog.51cto.com/3964020/1537308

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.