php Configuration Es1EN ES2en Startup parameters and configuration details

  • 2020-11-03 22:03:42
  • OfStack

Commit to a few directories

/usr/local/php/sbin/php-fpm
/usr/local/php/etc/php-fpm.conf
/usr/local/php/etc/php.ini
1. Startup parameters of ES9en-ES10en


# test php-fpm configuration 
/usr/local/php/sbin/php-fpm -t
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf -t

# Start the php-fpm
/usr/local/php/sbin/php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf

# Shut down php-fpm
kill -INT `cat /usr/local/php/var/run/php-fpm.pid`

# restart php-fpm
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`

2. Detailed explanation of important parameters of ES14en-ES15en

pid = run/php-fpm.pid
#pid Settings, default in the installation directory var/run/php-fpm.pid , recommended to open 

error_log = log/php-fpm.log
# Error log, default in the installation directory var/log/php-fpm.log

log_level = notice
# The error level .  Available level is : alert (Must be dealt with immediately) , error (Error case) , warning (Warning situation) , notice ( 1 General important information) , debug (Debugging information) .  The default : notice.

emergency_restart_threshold = 60
emergency_restart_interval = 60s
# Said in emergency_restart_interval Appears within the set value SIGSEGV or SIGBUS The wrong php-cgi If the number of processes exceeds  emergency_restart_threshold A, php-fpm It will reboot gracefully. These two options 1 Keep the default values as usual. 

process_control_timeout = 0
# Sets the timeout for the child process to accept the multiplexed signal from the main process .  The available unit : s( seconds ), m( points ), h( hours ),  or  d( day )  The default units : s( seconds ).  The default value : 0.

daemonize = yes
# The background to perform fpm, The default value is yes , if for debugging no . 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 Listen on the port, i.e nginx In the php The address to be processed, 1 Normal default value is ok. Available format is : 'ip:port', 'port', '/path/to/unix/socket'.  Each process pool needs to be set .

listen.backlog = -1
#backlog The number, -1 Indicates unlimited, depending on the operating system, and just comment it out. backlog References: http://www.3gyou.cc/?p=41

listen.allowed_clients = 127.0.0.1
# Allow access to FastCGI The process of IP To set up any To not limit IP , if you want to set the other host's nginx You can also visit this one FPM The process, listen Place to set the cost to be accessible IP . The default value is any . Each address is separated by a comma .  If not set or null, any server is allowed to request a connection 

listen.owner = www
listen.group = www
listen.mode = 0666
#unix socket Set options if used tcp Method access, here annotation can be. 

user = www
group = www
# Start the account and group for the process 

pm = dynamic # For a dedicated server, pm You can set it to static . 
# How do you control child processes static and dynamic . If you choose to static , pm.max_children Specifies a fixed number of child processes. If you choose to dynamic , then it is determined by the following parameters: 
pm.max_children # , the maximum number of child processes 
pm.start_servers # , number of processes at startup 
pm.min_spare_servers # Is guaranteed to have a minimum number of free processes, and if the free process is less than this, a new child process is created 
pm.max_spare_servers # , to ensure the maximum number of free processes, if the free process is greater than this value, this is cleaned up 

pm.max_requests = 1000
# Sets the number of requests to be served before each child process is resurrected .  For a possible memory leak 3 The square module is very useful .  If I set it to  '0'  the 1 On request .  Is equivalent to  PHP_FCGI_MAX_REQUESTS  The environment variable .  The default value : 0.

pm.status_path = /status
#FPM The url of the status page .  If it's not set ,  The status page cannot be accessed .  The default value : none. munin Monitoring will be used 

ping.path = /ping
#FPM Monitoring page ping The url .  If it's not set ,  Can't be accessed ping page .  This page is used for external detection FPM Is alive and can respond to requests .  Note that you must begin with a slash  (/) . 

ping.response = pong
# Used to define ping The return of the request corresponds .  Return to  HTTP 200  the  text/plain  Format text .  The default value : pong.

request_terminate_timeout = 0
# Sets the timeout for a single request .  This option might be correct php.ini Set in the 'max_execution_time' There is no script that will stop running for some special reason .  Set to  '0'  said  'Off'. When it comes up so often 502 You can try to change this option if an error occurs. 

request_slowlog_timeout = 10s
# when 1 After requesting the timeout period for this setting, the corresponding PHP The call stack information is written to the slow log in its entirety .  Set to  '0'  said  'Off'

slowlog = log/$pool.log.slow
# Logging of slow requests , Cooperate with request_slowlog_timeout use 

rlimit_files = 1024
# Set the file to open the descriptor rlimit limit .  The default value :  System definition values by default open handle is 1024 , you can use  ulimit -n See, ulimit -n 2048 Modification. 

rlimit_core = 0
# Set up the core rlimit Maximum limit value .  Available value : 'unlimited'  , 0 Or positive integer .  The default value :  System definition value .

chroot =
# The startup Chroot directory .  The directory defined needs to be an absolute path .  If it's not set ,  the chroot Don't be used .

chdir =
# Set up the boot directory and it will start automatically Chdir To the directory .  The directory defined needs to be an absolute path .  The default value :  Current directory, or / Directory ( chroot When) 

catch_workers_output = yes
# Redirect during run stdout and stderr To the main error log file .  If it's not set , stdout  and  stderr  Will be based on FastCGI Rule is redirected to  /dev/null .  The default value :  empty .

3. Sorting out common mistakes and solutions

1. Resource problems caused by request_terminate_timeout
Setting the value of request_terminate_timeout to 0 or for too long can cause resource problems with file_get_contents.

If the remote resource requested by file_get_contents reacts too slowly, file_get_contents will be stuck there without timeout. We know that max_execution_time in ES40en.ini can set the maximum execution time for the PHP script, but in ES46en-ES47en (ES48en-ES49en), this parameter does not work. What really controls the maximum execution time of the PHP script is the request_terminate_timeout parameter in the ES51en-ES52en.conf configuration file.

The default value of request_terminate_timeout is 0 seconds, which means that the PHP script will execute straight ahead. Thus, when all the ES63en-ES64en processes are stuck in the file_get_contents() function, the WebServer of Nginx+PHP can no longer handle the new PHP request, and Nginx returns "502 Bad Gateway" to the user. It is necessary to modify this parameter to set the maximum execution time of 1 PHP script, but the symptoms should not be treated. For example, change to 30s, if file_get_contents() gets the content of the web page slowly, this means that 150 ES80en-ES81en processes can only handle 5 requests per second, WebServer is also difficult to avoid "502 Bad Gateway". The solution is to set request_terminate_timeout to 10s or a reasonable value, or to add a timeout parameter to file_get_contents.


$ctx = stream_context_create(array(
    'http' => array(
        'timeout' => 10    // Set up the 1 A timeout in seconds 
    )
));

file_get_contents($str, 0, $ctx);

2. Improper configuration of max_requests parameter may cause intermittent 502 error:

pm.max_requests = 1000

Sets the number of requests to be served before each child process is reborn. This is useful for 3rd party modules where there may be memory leaks. If set to '0 ', 1 is directly requested. This is equivalent to the PHP_FCGI_MAX_REQUESTS environment variable. Default: 0.
This configuration means that an ES106-CGI process automatically restarts when the number of requests handled by that process accumulates to 500.
But why restart the process?
1 In general, we use some third side libraries of PHP more or less in the project. These third side libraries often have memory leakage problems. If the PROCESS of PHP-ES112en is not restarted regularly, the memory usage is bound to increase continuously. Therefore, ES113en-ES114en, as the manager of ES115en-ES116en, provides such a monitoring function to restart the ES117en-ES118en process that requests the specified number of times to ensure that the memory usage does not increase.
It is this mechanism that often leads to 502 errors on highly concurrent sites, which I suspect is due to PHP-ES121en not handling the request queue coming from NGINX. However, I'm still using PHP 5.3.2, so I don't know if this problem still exists in PHP 5.3.3.
Our solution for now is to make this value as large as possible to minimize the number of times PHP-ES127en redoes SPAWN, while also improving overall performance. In our own actual production environment, we found that the memory leak was not obvious, so we set this value to be very large (204800). You should set this value according to your actual situation, not blindly increase it.
After all, the purpose of this mechanism is to ensure that ES130en-ES131en does not consume too much memory, so why not deal with it by detecting memory? I strongly agree with Gao chunhui that it would be a better solution to restart the PHP-ES133en process by setting the peak internal occupancy of the process.

3, php-ES137en slow log, debug and abnormal detection artifact:
request_slowlog_timeout sets a timeout parameter and slowlog sets the location of slow logs


tail -f /var/log/www.slow.log

The above command shows the slow execution of the php procedure.
You can see that the network read over, Mysql query too slow problems often occur, according to the prompt message and then check the problem has a very clear direction.


Related articles: