"Rollup" PHP-FPM Configuration optimizations (RPM)

Source: Internet
Author: User
Tags stop script vps

----------------------- turn on php-fpm slow script log


Request_slowlog_timeout = 30s
Slowlog =/usr/local/php/var/log/php-fpm.log.slow

Typical log content is as follows:

[15-apr-2012 20:56:19] [Pool www] pid 9748
Script_filename =/var/www/html/htdocs/www.xxx.com/xxx.php
[0x00000000090bc270] file_get_contents ()/var/www/html/htdocs/www.xxx.com/xxx.php:81

Slow script files, specific lines, functions and so on are all very detailed records, the optimization of the work is relatively easy.

Request_terminate_timeout = 120

#表示等待120秒后, end those PHP scripts that do not end automatically to free up resources that are consumed.


When PHP is running in PHP-FPM mode, the max_execute_time of the php.ini configuration is invalid and another configuration item needs to be configured in php-fpm.conf: Request_terminate_timeout; The following is an explanation of the official documentation:
Request_terminate_timeout–the timeout (in seconds) for serving a single request after which the worker process would be t Erminated. Should is used when the ' max_execution_time ' ini option does not the stop script execution for some reason. Default: "5s". Note: ' 0s ' means ' off '
Note: Set_time_limit () and max_execution_time only affect the time that the script itself executes. Any script execution that occurs such as a system call, flow operations, database operations, and so on that takes place in systems () does not include the maximum time.

[Global]
PID =/dev/shm/pid/php-fpm.pid
Error_log =/usr/local/php/var/log/php-fpm.log
Log_level = Notice
[WWW]
Listen = 127.0.0.1:9000
; listen.allowed_clients = 192.168.1.17,127.0.0.1,192.168.1.75
user = www
Group = www
PM = dynamic
Pm.max_children = 2000
Pm.start_servers = 10
Pm.min_spare_servers = 5
Pm.max_spare_servers = 200
Pm.max_requests = 12000
Pm.process_idle_timeout = 10s
Request_terminate_timeout = 120
Request_slowlog_timeout = 30s
Slowlog =/usr/local/php/var/log/php-fpm.log.slow


Here are some of the parameters that relate to this, namely 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 be noted in the description of 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 pm.max_children this parameter takes effect. The system turns on the number of PHP-FPM processes that are set.
If the DM is set to dynamic, then the Pm.max_children parameter is invalidated and the next 3 parameters take effect.
The system will start the Pm.start_servers PHP-FPM process at the beginning of the PHP-FPM run,
The number of PHP-FPM processes is then dynamically adjusted between Pm.min_spare_servers and pm.max_spare_servers based on the requirements of the system.

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 number can also be based on memory/30m, such as 8GB memory can be set to 100,
Then the php-fpm of 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 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.

============================= 127.0.0.1 Monitor Native IP

Php-fpm.conf

Listen = 127.0.0.1:9000

Nginx.conf


Location ~ ^ (. +\.php) (. *) $ {
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Include fcgi.conf;
}

"Rollup" PHP-FPM Configuration optimizations (RPM)

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.