In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "introduction of php-fpm parameter configuration and parameter optimization description under linux system". In daily operation, it is believed that many people have doubts about the introduction of php-fpm parameter configuration and parameter optimization explanation under linux system. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful for you to answer the doubt of "introduction of php-fpm parameter configuration and parameter optimization description under linux system". Next, please follow the editor to study!
Detailed explanation of important parameters of php-fpm.conf
Pid = run/php-fpm.pid
# pid setting. Default is the var/run/php-fpm.pid in the installation directory. It is recommended to enable it.
Error_log = log/php-fpm.log
# error log, default is the var/log/php-fpm.log in the installation directory
Log_level = notice
# error level. Available levels are: alert (must be dealt with immediately), error (error condition), warning (warning condition), notice (general important information), debug (debugging information). Default: notice.
Emergency_restart_threshold = 60
Emergency_restart_interval = 60s
# indicates that if the number of php-cgi processes with SIGSEGV or SIGBUS errors within the value set by emergency_restart_interval exceeds emergency_restart_threshold, php-fpm will restart gracefully. These two options generally remain at their default values.
Process_control_timeout = 0
# set the timeout for the child process to accept the main process multiplexing signal. Available units: s (seconds), m (minutes), h (hours), or d (days) default units: s (seconds). Default value: 0.
Daemonize = yes
# fpm is executed in the background. The default value is yes, which can be changed to no for debugging. In FPM, you can use different settings to run multiple process pools. These settings can be set individually for each process pool.
Listen = 127.0.0.1 9000
# fpm listening port, that is, the address processed by php in nginx. The default value is generally fine. The available formats are: 'ip:port',' port','/ path/to/unix/socket'. Each process pool needs to be set up.
Listen.backlog =-1
The number of # backlog.-1 means unlimited, which is determined by the operating system. Just comment out this line.
Listen.allowed_clients = 127.0.0.1
# allow access to the IP of the FastCGI process, and set the any to unrestricted IP. If you want to set the nginx of other hosts to access this FPM process, you need to set a cost-accessible IP at the listen. The default value is any. Each address is separated by a comma. If it is not set or empty, any server is allowed to request a connection
Listen.owner = www
Listen.group = www
Listen.mode = 0666
# unix socket setting options. If you use tcp access, you can simply comment here.
User = www
Group = www
# account and group to start the process
Pm = dynamic
# for dedicated servers, pm can be set to static.
# how to control child processes, the options are static and dynamic. If static is selected, pm.max_children specifies a fixed number of child processes. If dynamic is selected, it is determined by the following on parameter:
Pm.max_children #, maximum number of child processes
Pm.start_servers #, number of processes at startup
Pm.min_spare_servers # to keep the number of idle processes to a minimum, and if the idle processes are less than this value, create a new child process
Pm.max_spare_servers #, which guarantees the maximum number of idle processes. If the idle processes are greater than this value, clean up.
Pm.max_requests = 1000
# set the number of requests for services before each child process is reborn. It is very useful for third-party modules that may have memory leaks. If set to'0', the request will be accepted all the time. Equivalent to the PHP_FCGI_MAX_REQUESTS environment variable. Default value: 0.
Pm.status_path = / status
# URL of the FPM status page. If it is not set, the status page cannot be accessed. Default value: none. Munin monitoring will use
Ping.path = / ping
# ping URL of the FPM monitoring page. If it is not set, the ping page cannot be accessed. This page is used to externally detect whether the FPM is alive and can respond to requests. Please note that it must begin with a slash (/).
Ping.response = pong
# used to define the response of a ping request. Returns text in text/plain format as HTTP 200. Default value: pong.
Request_terminate_timeout = 0
# set the timeout abort time for a single request. This option may be useful for scripts in the php.ini setting where 'max_execution_time' does not stop running for some special reason. Set to'0' means' Off'. You can try to change this option when 502 errors occur frequently.
Request_slowlog_timeout = 10s
When a timeout for this setting is requested, the corresponding PHP call stack information is fully written to the slow log. Set to'0' means' Off'
Slowlog = log/$pool.log.slow
# logging of slow requests for use with request_slowlog_timeout
Rlimit_files = 1024
# sets the rlimit limit for file opening descriptors. Default: the system-defined value defaults to open handle 1024, which can be viewed using ulimit-n and modified by ulimit-n 2048.
Rlimit_core = 0
# set the maximum limit of core rlimit. Available values: 'unlimited', 0, or positive integer. Default value: system-defined value.
Chroot =
# Chroot directory at startup. The defined directory needs to be an absolute path. If it is not set, chroot is not used.
Chdir =
# set the startup directory, which will be automatically Chdir at startup. The defined directory needs to be an absolute path. Default value: current directory, or / directory (on chroot)
Catch_workers_output = yes
# redirect the stdout and stderr during the run to the main error log file. If not set, stdout and stderr will be redirected to / dev/null according to the rules of FastCGI. Default value: empty.
Php-fpm parameter tuning
Pm = dynamic
Indicates which process quantity management method is used
Dynamic indicates that the number of php-fpm processes is dynamic, starting with the number specified by pm.start_servers. If there are more requests, it will automatically increase to ensure that the number of idle processes is not less than pm.min_spare_servers. If the number of processes is large, it will be cleaned accordingly to ensure that the number of redundant processes is not more than pm.max_spare_servers.
Static indicates that the number of php-fpm processes is static, and the number of processes is always the number specified by pm.max_children, and no longer increases or decreases.
Pm.max_children = 300; number of php-fpm processes opened in static mode
Pm.start_servers = 20; number of starting php-fpm processes in dynamic mode
Pm.min_spare_servers = 5; minimum number of php-fpm processes in dynamic mode
Pm.max_spare_servers = 35; maximum number of php-fpm processes in dynamic mode
If pm is static, then only the parameter pm.max_children takes effect. The system will open a set number of php-fpm processes
If pm is dynamic, then the pm.max_children parameter is invalid and the next three parameters take effect. The system will start pm.start_servers php-fpm processes when php-fpm starts, and then dynamically adjust the number of php-fpm processes between pm.min_spare_servers and pm.max_spare_servers according to the needs of the system.
So, which pm method is better for our server? In fact, like Apache, running PHP programs will more or less have memory leaks after execution. This is why a php-fpm process takes up only about 3 megabytes of memory at the beginning and rises to 20-30 megabytes after a period of time.
For servers with large memory (such as more than 8G), it is actually more appropriate to specify a static max_children, because this does not require additional process number control and will improve efficiency. Because frequently switching php-fpm processes can sometimes lag, it is better to turn on static when the memory is large enough. The amount can also be obtained according to memory / 30m, for example, 8GB memory can be set to 100, so the memory consumed by php-fpm can be controlled in the appearance of 2G-3G. If the memory is slightly smaller, such as 1G, then specifying the number of static processes is more conducive to the stability of the server. This ensures that php-fpm only gets enough memory and allocates a small amount of memory to other applications, which will make the system run more smoothly.
For servers with small memory, such as 256m VPS, even if 10 php-cgi processes consume 200m of memory based on a 20m memory, the crash of the system should be normal. Therefore, you should try to control the number of php-fpm processes, generally clear the memory consumed by other applications, give it a small amount of static, it will make the system more stable. Or use dynamic, because dynamic will end the excess processes, can reclaim and release some memory, so it is recommended on servers or VPS with less memory. The specific maximum quantity is obtained according to memory / 20m. For example, for the 512m VPS, it is recommended that the pm.max_spare_servers be set to 20. As for pm.min_spare_servers, it is recommended to set it according to the load of the server, and the more appropriate value is between 5 and 10.
200 is fine on a server with 4G memory (64 is the best for my 1G tester, it is recommended to use stress testing to get the best value)
Pm.max_requests = 10240
The biggest problem in the nginx php-fpm configuration process is internal leakage: the server's load is not large, but the memory footprint increases rapidly, and soon eats the memory and then begins to eat the swap partition, and the system quickly dies! In fact, according to the official introduction, there is no memory leak in php-cgi. After each request is completed, php-cgi will reclaim memory, but will not release it to the operating system, which will result in a large amount of memory being occupied by php-cgi.
The official solution is to lower the value of PHP_FCGI_MAX_REQUESTS. If php-fpm is used, the corresponding php-fpm.conf is max_requests. This value means how many requests will restart the thread. We need to lower this value appropriately so that php-fpm can automatically free memory, not 51200 as mentioned on the Internet. In fact, there is another value associated with it, max_children. This is how many processes php-fpm will set up at a time, so the actual memory consumption is the memory used by max_children*max_requests* per request, so we can estimate the memory usage so that we don't have to write scripts to kill.
Request_terminate_timeout = 30
Maximum execution time, which can also be configured in php.ini (max_execution_time)
Request_slowlog_timeout = 2; enable slow log
Slowlog = log/$pool.log.slow; slow log path
Rlimit_files = 1024; increase the limit of php-fpm open file descriptor
The parameters of php-fpm.conf say that you should remember it as long as you read it a few more times. As for the php-fpm performance scheme, it should be determined according to the actual situation, and the best configuration scheme should be obtained by testing several times.
At this point, the study of "introduction to php-fpm parameter configuration and parameter optimization instructions under the linux system" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.