


php-fpm.conf configuration file Chinese and important parameter descriptions
php-fpm workflow
php-fpm The full name is PHP FastCGI Process Manager
After php-fpm is started, it will first read php.ini, and then read the corresponding conf configuration file. The conf configuration can override the php.ini configuration.
After starting php-fpm, a master process will be created to listen to port 9000 (configurable). The master process will create several sub-processes based on fpm.conf/www.conf. The sub-processes are used to handle actual Business.
When a client (such as nginx) connects to port 9000, the idle child process will accept it by itself. If all child processes are busy, the new connection to be accepted will be put into the queue by the master. , waiting for the fpm sub-process to be idle;
The length of the queue that stores semi-connections to be accepted is configured by listen.backlog.
Related learning recommendations: php programming (video)
All relative paths in the configuration are relative to the installation of php path.
In addition to the php-fpm.conf configuration file, there are usually other *.conf configuration files (or not, configure directly in php-fpm.conf) for configuring the process pool and different processes. Pools can be executed by different users, listen to different ports, and handle different tasks; multiple process pools share a global configuration.
include=/opt/remi/php56/root/etc/php-fpm.d/*.conf Load other configuration files.
php-fpm global configuration parameters Chinese description:
pid = /opt/remi/php56/root/var/run/php-fpm/php-fpm.pid
#pid process file, default is none.error_log = /opt/remi/php56/root/var/log/php-fpm/error.log
#Error log location, default: installation path #INSTALL_PREFIX#/log/php-fpm. log. If set to syslog, the log will be sent to the syslogd service without being written to the file.syslog.facility = daemon
#Write the log into the system log. Linux is not familiar enough yet, so ignore it for now.syslog.ident = php-fpm
#System log identifier. If multiple fpm processes are running, you need to use this to distinguish whose log it belongs to.log_level = notice
#Log level, default notice, optional: alert, error, warning, notice, debugemergency_restart_threshold = 60
#With the following emergency_restart_interval parameteremergency_restart_interval = 60s
#If the number of child processes with SIGSEGV or SIGBUS exceeds the value set by the emergency_restart_threshold parameter within the time set by this parameter, then fpm will restart gracefully. A value of 0 means off this function. , available units are: s seconds, m minutes, h hours, d days.process_control_timeout = 0
#Set the timeout for the child process to accept the main process multiplexing signal. I understand this every day. After this time, it cannot be reused?process.max = 128
#When dynamically managing child processes, fpm can fork the most number of processes. 0 means no limit. This is the total number of child processes that can be started by all process pools. Use with caution.process.priority = -19
# Set the priority of the child process, which is effective when the master process is started as the root user; if not set, the child process will inherit the priority of the master process, and the value range is - 19 (highest) to 20 (lowest), not set by default.daemonize = yes
#Set to no for debugging bugs, the default is yes.rlimit_files = 1024
#Set the maximum number of files that the master process can open. The default is the system value.rlimit_core = 0
#Master process core rlimit limit value; optional unlimited or an integer >=0, the default is the system value.events.mechanism = epoll
#Event processing mechanism, automatic detection by default, optional values: select, poll, epoll (linux>=2.5.44), kqueue, /dev/poll, portsystemd_interval = 10s
#When fpm is set as a system service, how often the status is reported to the server, the units are s, m, h.
php-fpm process pool configuration pool Definitions:
You can run anything under different listening ports and different management options. There is no limit to the number of pools;
The name of the pool is used for logs and stats.
user = apache
group = apache
#Run pool fpm with the permissions of which user and group.
Use apache to access certain directories like httpd service
listen = 127.0.0.1:9000
#The listening ip and port can be /path/to/unix/socket To monitor unix socket, the performance is better.listen.backlog = 65535
#The size of the unaccepted socket queue, -1 on FreeBSD and OpenBSD, the default is 65535 on other platforms, important when concurrency is high, reasonable settings will process queued requests in a timely manner; too There is too much backlog in the conference. After processing, nginx waits for timeout and disconnects the socket connection with fpm, which is a failure. Do not use -1, it is recommended to be above 1024, preferably a power of 2.#A pool shares a backlog queue, and all pool processes go to this queue to accept connections.
#The maximum number is limited by the system configuration cat /proc/sys/net/core/somaxconn, system configuration modification: vim /etc/sysctl.conf, add net.core.somaxconn = 2000, the maximum is 2000, and then php The maximum backlog can be up to 2000.
listen.owner = apache
listen.group = apache
listen.mode = 0660
#When using the socket connection method, specify the unix socket The user with permissions is the same as the running user by default; when using tcp connection, you can comment out
listen.allowed_clients = 127.0.0.1
#Set the address that is allowed to connect to fpm, for example, nginx will connect, multiple The addresses are separated by commas. If not configured, any address can be connected by default.process.priority = -19
#The permissions of the pool process also require the master process to be the root user. It is the same as the global one. If not set, the priority of the master process will be inherited.pm = dynamic
# Child process management method at startup, optional values: static (specified number created at startup), dynamic (created according to the situation at startup, at least one), ondemand (start Child processes are not created at this time, and will be created only when needed)pm.max_children = 5
#This pool can have up to 5 processes at the same time, and all three management methods must be configuredpm. start_servers = 2
#Create 2 child processes when fpm starts, only applicable to dynamic dynamic management methodpm.min_spare_servers = 2
#At least 2 child processes will be maintained when the server is idle. If this number is not enough, it will Create, only applicable to dynamic dynamic management methodpm.max_spare_servers = 3
#There must be at most a few servers when they are idle, if there are too many, they will be killed, only applicable to dynamic dynamic management methodpm .process_idle_timeout = 10s
#The child process will be killed after being idle for 10s.pm.max_requests = 500
#Each child process will be recycled after processing a maximum of 500 requests, which can prevent memory leaks.pm.status_path string
#The URL of the FPM status page. If not set, the status page cannot be accessed. Default: None.
ping.path string
#The ping URL of the FPM monitoring page. If not set, the ping page cannot be accessed. This page is used to externally detect whether the FPM is alive and able to respond to requests. Note that it must start with a slash (/).
ping.response string
#Used to define the return response of the ping request. Returns text/plain formatted text as HTTP 200. Default value: pong.process.priority int
#Set the worker's nice(2) priority (if set). The value ranges from -19 (highest priority) to 20 (lower priority). Default value: Do not setprefix string
#The prefix used when detecting the pathaccess.log = var/log/$pool.access.log
#Access file log , is of little use. For example, yii2 records access to index.php every time, but only records the real PHP file.slowlog = var/log/$pool.log.slow
#The log of PHP file execution that is too slow will accurately record which line of code is too slow. This is very useful when setting the time. Take effect.request_slowlog_timeout = 2s
#Slow log will be written if this running time is exceededrequest_terminate_timeout = 3s
#The timeout of a single request, sometimes the maximum execution set by php.ini If the time has not taken effect, this will kill the request that took too long to execute.rlimit_files = 1024
#The maximum number of open handles, the default is the system value.rlimit_core = 0
#The maximum number of cores used, the default is system allocation.chroot = /path
#The path must be an absolute path. Changing the directory of the child process can isolate the process's reading and writing of the file system from the actual operating system file system, which is good for security.chdir = /var/www
#Change the current working directory, you can use a relative path, the default is the current directory or chroot.
catch_workers_output = yes
#Redirect standard output stdout and standard error stderr to the main error log. If not set, these two logs will be directed to /dev/null. Under high load conditions, This configuration will cause the page to be delayed for several milliseconds and is not enabled by default.clear_env = no
#Whether to clear the environment variables when creating the work process, if yes, then the child process getenv() will not be able to access $_ENV and $_SERVER.security.limit_extensions = .php .php3 .php4 .php5
#For security, limit the script suffix that can be executed#Specify additional php.ini configuration for the current pool, such as Specify where the error log of the current pool is written
php_value/php_flag
#The content of php.ini can be set and can be overridden by ini_setphp_admin_value/php_admin_flag
#This is the same as above , but will not be overwritten by ini_set.#When flag is set, the value can only be on, off, 1, 0, true, false, yes or no. Other types of values need to use value.
php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 32M
#When setting `disable_functions` and `disable_classes` in this method, the settings of php.ini will not be overwritten, but will only be appended.
Note: PHP configuration values are set through php_value or php_flag, and will overwrite the previous value.
Disable_functions or disable_classes The values defined in php.ini will not be overwritten, but the new settings will be appended to the original values.
The value defined using php_admin_value or php_admin_flag cannot be overridden by ini_set() in PHP code.
Since 5.3.3, PHP settings can also be set through the web server.
nginx communicates with php-fpm through unixsock:
Applicable scenarios: nginx and php-fpm are on the same server. In this case, unixsocket inter-process communication can be used directly , without using TCP port communication, you can save time to create a connection, thereby improving performance.
1. Set the listen of php-fpm to /opt/remi/php56/root/var/run/php-fpm/php567-fpm.sock (relative path can be used), and then restart fpm and it will automatically Create the php567-fpm.sock file
2. Change the fastcgi_pass parameter of nginx to unix:/opt/remi/php56/root/var/run/php-fpm/php567-fpm.sock; through php567- To communicate with fpm, the fpm.sock file needs to ensure that nginx has permission to access the php567-fpm.sock file.
Summary:
The sock file can be created anywhere, as long as fpm has the permission to write the file in that directory and nginx has the permission to read it. The tcp connection will be more stable because the TCP protocol ensures the correctness of the data, but sock has fewer data copies and context switches, and consumes less resources. However, sock can only be used when nginx and fpm are on the same machine.
php-fpm process status monitoring
1. nginx configuration: when encountering a status request, forward it directly to php
location ~^/status$ {
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}
2. Fpm configuration: pm.status_path = /status
3. Then restart fpm and nginx and access it in the browser to see:
The results are displayed in text/plain by default. You can pass the parameters ?json/html/xml to get the results in json and other formats respectively; the parameter full can view the details of each sub-process
pool Process pool name
process manager Process management method
start time When did the process start
start since How many seconds has the process been running
accepted conn How many connections has the pool accepted in total
listen queue The number of connections waiting for accept
max listen queue After fpm is started, the highest number of connections waiting for accept in history
listen queue len The maximum length of the configured listening queue is limited by `listen.backlog` and the system `cat /proc/sys/net/core/somaxconn`, whichever is the smallest value
idle processes Idle Number of processes
active process The number of working processes (with restrictions, it is the total number of child processes)
total processes The total number of child processes
max active processes After fpm is started, the maximum number of processes working simultaneously in history
max children reached When the process management mode is 'dynamic' and 'ondemand', this value is the number of times the master creates more child processes when there are not enough child processes.
slow requests The number of slow requests
Under the full parameter
pid child process ID;
state child process status (Idle, Running, ... );
start time The time when the child process started;
start since How many seconds has it been running since the child process started;
requests How many requests has the current child process processed in total;
request duration The number of nanoseconds the request takes;
request method request method (GET, POST, ...);
request URI request parameter;
content length POST request, the requested content length;
user - the user (PHP_AUTH_USER) (or '-' if not set);
script which php file is requested;
last request cpu The cpu resources consumed by the last request
last request memory The peak memory consumed by the last request
If the process is idle, then this information is recorded The relevant data of this request, otherwise it is the relevant data of this current request.
Backlog configuration issue
An fpm sub-process can only handle one request at the same time. If the backlog is set too large, requests initiated by clients such as nginx will never have an fpm sub-process. When accepting, nginx will directly disconnect the connection. When fpm is busy and then accept, it will be found that it is disconnected, so an error will be reported. If the backlog is set too small, when the amount of access is large, all fpm sub-processes will be busy, and the backlog will be full, and new connections will be rejected. At this time, if nginx requests again, it will be directly rejected. Therefore, backlog parameters need to be set appropriately.
As long as the system defaults are used for most of the parameters, we only need to know a few more important parameter settings. When they are used, we can look back for relevant instructions
Related recommendations: Programming Video Course
The above is the detailed content of php-fpm.conf configuration file Chinese and important parameter descriptions. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use php-fpm for high-performance tuning PHP is a very popular server-side scripting language that is widely used to develop web applications and dynamic websites. However, as traffic increases, the performance of your PHP application may suffer. In order to solve this problem, we can use php-fpm (FastCGIProcessManager) for high-performance tuning. This article will introduce how to use php-fpm to improve the performance of PHP applications and provide code examples. one,

If you bought your laptop from a mobile operator, you most likely had the option to activate an eSIM and use your cellular network to connect your computer to the Internet. With eSIM, you don't need to insert another physical SIM card into your laptop because it's already built-in. It is very useful when your device cannot connect to the network. How to check if my Windows 11 device is eSIM compatible? Click the Start button and go to Network & Internet > Cellular > Settings. If you don't see the "Cellular" option, your device doesn't have eSIM capabilities and you should check another option, such as using your mobile device to connect your laptop to a hotspot. In order to activate and

How to use PHP-FPM optimization to improve the performance of PrestaShop applications. With the rapid development of the e-commerce industry, PrestaShop has become the e-commerce platform chosen by many merchants. However, as the size of the store increases and the number of visits increases, the PrestaShop application may encounter performance bottlenecks. In order to improve the performance of the PrestaShop application, a common method is to use PHP-FPM to optimize and improve the application's processing capabilities. PHP-FPM (FastCGI

How to Improve the Performance of WooCommerce Applications Using PHP-FPM Optimization Overview WooCommerce is a very popular e-commerce plugin for creating and managing online stores on WordPress websites. However, as your store grows and traffic increases, WooCommerce apps can become slow and unstable. To solve this problem, we can use PHP-FPM to optimize and improve the performance of WooCommerce applications. What is PHP-FP

Why should we write the fixed file of the configuration file? We can directly write it as a .py file, such as settings.py or config.py. The advantage of this is that we can directly import parts of it through import in the same project; but if we need to use it in other When sharing configuration files on non-Python platforms, writing a single .py is not a good choice. At this time we should choose a common configuration file type to store these fixed parts. Currently, the commonly used and popular configuration file format types mainly include ini, json, toml, yaml, xml, etc. We can access these types of configuration files through standard libraries or third-party libraries.

Overview of using php-fpm connection pool to improve database access performance: In web development, database access is one of the most frequent and time-consuming operations. The traditional method is to create a new database connection for each database operation and then close the connection after use. This method will cause frequent establishment and closing of database connections, increasing system overhead. In order to solve this problem, you can use php-fpm connection pool technology to improve database access performance. Principle of connection pool: Connection pool is a caching technology that combines a certain number of databases

Setting up a wireless network is common, but choosing or changing the network type can be confusing, especially if you don't know the consequences. If you're looking for advice on how to change the network type from public to private or vice versa in Windows 11, read on for some helpful information. What are the different network profiles in Windows 11? Windows 11 comes with a number of network profiles, which are essentially sets of settings that can be used to configure various network connections. This is useful if you have multiple connections at home or office so you don't have to set it all up every time you connect to a new network. Private and public network profiles are two common types in Windows 11, but generally

Recently, many Win10 system users want to change the user profile, but they don’t know how to do it. This article will show you how to set the user profile in Win10 system! How to set up user profile in Win10 1. First, press the "Win+I" keys to open the settings interface, and click to enter the "System" settings. 2. Then, in the opened interface, click "About" on the left, then find and click "Advanced System Settings". 3. Then, in the pop-up window, switch to the "" option bar and click "User Configuration" below.
