The configuration file is usually stored in the PHP directory etc/php-fpm.d/*.conf
Max_children Maximum number of child processes
pm.max_children = 100
Maximum number of child processes, the more the better, usually each PHp-CGI memory consumption is about 20M
If the maximum number is set to 100, phP-CGI will consume less than 2000M at peak times
If this value is set to a small value, the waiting time for the request will be 502 timeout
4 GB memory server can be set to 200
Start_servers Number of child processes created at startup
pm.start_servers = 20
Pm. start_Servers: Number of child processes created at startup, 10 to 20, or 400 MB of memory for 20
pm.max_requests = 10240
To avoid memory leaks, phP-FPM has a mechanism that automatically restarts a PHp-CGI process when the number of requests it handles reaches this configuration. This often results in error 502 in high concurrency
The solution is to set this value to a larger value to reduce the number of process restarts and reduce error 502 in high concurrency cases.
Request_terminate_timeout Timeout of a single request
request_terminate_timeout = 400
The timeout duration of a single request, after which the process is terminated, nginx finds that the signal is broken and returns error 502 to the client.
This does not conflict with the max_execution_time configuration in php.ini, which takes effect first.
It is recommended that this value be set to 400 seconds because there is a request waiting for the third-party interface in the program. A longer value will not cause error 502
Min_spare_servers Guarantees the minimum number of idle processes
pm.min_spare_servers = 10
The minimum number of idle processes is guaranteed. If the number of idle processes is smaller than this value, a new child process is created
pm.max_spare_servers = 30
Ensure that the number of idle processes reaches the maximum value. If the number of idle processes exceeds the threshold, clear the idle process
rlimit_files = xxx
Sets the rlimit limit for the file opening descriptor, which can be viewed using ulimit -n
other
pm.status_path = /status
Can be used to view phP-FPM running conditions, configuration open in nginx proxy forwarding, you can access in the browser
/status Displays the meanings of parameters:
Pool – FPM Pool name, most of which is WWW
Process Manager – Process management mode
Values: static, dynamic, or ondemand.dynamic
Start time – Start time
If phP-fpm is reloaded, the time is updated
Start since – Run time
Accepted CONN – The number of requests accepted by the current pool
Listen Queue – Request waiting queue
If this value is not 0, increase the number of FPM processes
Max Listen Queue – Maximum number of request waiting queues
Listen Queue len – Length of the socket waiting queue
Idle processes – The number of idle processes
Active Processes – The number of active processes
Total Processes – The total number of processes
Max Active Processes – Maximum number of active processes (starting FPM)
Max children reached – Number of times the maximum number of processes is limited
If this number is not 0, then your maximum number of processes is too small, please increase it.
Slow requests — Number of slow requests with PHP-FPM slow-log enabled
You can also append the url? Full to view more detailed status. Parameter values are as follows:
Pid – Process PID. You can kill the process individually.
State – Status of the current process (Idle, Running,…)
Start time – Start date of the process
Start since – How long the current process is running
Requests – How many requests were processed by the current process
Request duration – Request duration (subtle)
Request method – Request method (GET, POST,…)
Request URI – Request URI
Content Length – Length of request content (POST only)
User — user (PHP_AUTH_USER) (or ‘-‘ if not set)
Script — PHP script (or ‘-‘ if not set)
Last Request CPU – CPU usage of the last request.
Last Request memorythe – Memory used by the last request
Nginx forwarding configuration:
location /status {
Fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
Others: ping.path = /ping
Used externally to check if the FPM is alive and can respond to requests
Nginx forwarding configuration: location /ping {fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; }
Note: The macOS system has limitations on the number of processes, open files, etc. For easy operation, it is directly tested under Linux.
Reload the configuration file after modifying the configuration:
Ps aux | grep PHP – run FPM get Ss type pid kill USR2 pid,
Reprinted source
Blog.csdn.net/u012628581/… Thanks to the author