This article provides a detailed analysis of the php-fpm parameters. For more information, see
Ps aux | grep php-fpm | more
View the total number of php-fpm instances
PID file location. the default value is null.
Location of the error log. default: Installation Path # INSTALL_PREFIX #/log/php-fpm.log.
Error level. available level: alert (must be handled immediately), error (error), warning (warning), notice (important information), debug (debugging information ). default value: notice.
If the child process receives the SIGSEGV or SIGBUS exit information number set by this parameter within the time set by emergency_restart_interval, FPM restarts. 0 indicates 'disabling this function'. default value: 0 (disabled ).
Emergency_restart_interval is used to set the interval of smooth restart. this helps solve the problem of shared memory usage in the accelerator. available unit: s (seconds), m (minutes), h (hours), or d (days ). default unit: s (seconds ). default value: 0 (off ).
Set the timeout time for the sub-process to receive the multiplexing signals of the main process. available unit: s (seconds), m (minutes), h (hours), or d (days) default unit: s (seconds ). default value: 0.
Set FPM to run in the background. set 'no' to keep FPM running in the foreground for debugging. default value: yes.
Run configuration section
In FPM, you can use different settings to run multiple process pools. These settings can be set separately for each process pool.
Set the address for receiving the FastCGI request. the available format is 'IP: port', 'port', '/path/to/unix/socket'. each process pool needs to be set.
Listen. backlog int
Set the length of the semi-join queue of listen (2). '-1' indicates no limit. default value:-1.
Listen. allowed_clients string
Set the IPV4 address of the server that allows connection to FastCGI. equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in PHP FastCGI (5.2.2 +. only applies to TCP listeners. each address is separated by a comma. if it is not set or empty, any server is allowed to request a connection. default value: any.
Listen. owner string
If this parameter is used, the Unix socket permission is set. in Linux, read and write permissions must be set for WEB server connection. in many BSD-derived systems, permissions can be ignored to allow free connection. default value: the account used for the operation, with the permission of 0666.
Listen. group string
See listen. owner.
Listen. mode string
See listen. owner.
Unix user running the FPM process. it must be set.
Unix user group in which FPM processes run. If no setting is set, the default user group is used.
Set how the process manager manages sub-processes. available values: static, dynamic. required.
Static-the number of sub-processes is fixed (pm. max_children ).
The number of dynamic-sub-processes is dynamically set based on the following configuration: pm. max_children, pm. start_servers, pm. min_spare_servers, pm. max_spare_servers.
Pm. max_children int
Number of sub-processes. when pm is set to static, it indicates creation. when pm is set to dynamic, it indicates maximum creation. it must be set.
This option sets the number of requests that can provide services at the same time. similar to the setting of MaxClients in Apache mpm_prefork and the PHP_FCGI_CHILDREN environment variable in common PHP FastCGI.
Pm. start_servers in
Set the number of child processes created at startup. this parameter is only used when pm is set to dynamic. default value: min_spare_servers + (max_spare_servers-min_spare_servers)/2.
Pm. min_spare_servers int
Set the minimum number of idle service processes. used only when pm is set to dynamic. required.
Pm. max_spare_servers int
Set the maximum number of idle service processes. used only when pm is set to dynamic. required.
Pm. max_requests int
Sets the number of service requests before each sub-process is reborn. it is very useful for third-party modules that may have memory leaks. if it is set to '0', the request is always accepted. equivalent to the PHP_FCGI_MAX_REQUESTS environment variable. default value: 0.
Pm. status_path string
The URL of the FPM status page. if not set, the page cannot be accessed. default value: none.
Ping. path string
The ping URL of the FPM monitoring page. If this parameter is not set, you cannot access the ping page. this page is used to check whether the FPM is alive and can respond to requests. Note that it must start with a slash (/).
Ping. response string
It is used to define the response of ping requests. The Returned text is in the text/plain format of HTTP 200. default value: pong.
Set the timeout duration of a single request. this option may apply to php. the 'max _ execution_time 'in ini settings is not useful for stopping the running script for some special reasons. set to '0' to 'off '. available units: s (econds) (default), m (inutes), h (ours), or d (ays ). default value: 0.
When a request times out, the corresponding PHP call stack information is completely written to the slow log. set to '0' to 'off '. available unit: s (seconds) (default), m (minutes), h (hours), or d (days ). default value: 0.
Slow Request Logging. default value: # INSTALL_PREFIX #/log/php-fpm.log.slow.
Scope: php-fpm.conf options
This option allows you to track and execute slow scripts and record them together with the call stack to log files. For example:
The recorded slow. log may look like this:
The code is as follows:
Sep 21 16:22:19. 399162 pid 29715 (pool default)
Script_filename =/local/www/stable/www/catalogue. php
[0x00007fff23618120] mysql_query ()/srv/stable/common/Database/class. MySQLRequest. php: 20
[0x00007fff23618560] getResult ()/srv/stable/common/Database/class. Facade. php: 106
[0x00007fff23618aa0] query ()/srv/stable/common/mysite.com/ORM/class.UsersMapper.php:99
[0x00007fff23618d60] resolveByID ()/srv/stable/common/mysite.com/ORM/class.User.php:629
[0x00007fff236193b0] getData ()/srv/stable/common/class. DataEntity. php: 90
[0x00007fff236195d0] load ()/srv/stable/common/mysite.com/ORM/class.User.php:587
[0x00007fff23619a00] getIsHidden ()/srv/stable/common/mysite.com/class.User.php:42
[0x00007fff2361a470] getName ()/local/www/stable/www/catalogue. php: 41
At the same time, the following records are saved in error. log:
Sep 21 16:22:19. 399031 [WARNING] fpm_request_check_timed_out (), line 135: child 29715, script'/local/www/stable/www/catalogue. php '(pool default) executing too slow (5.018002 sec), logging
As you can see in the example, the script runs for more than five seconds, probably because of the slow mysql response (top backtrace ).
Set the rlimit limit for the file opening descriptor. default value: System defined value.
Set the maximum limit value of the core rlimit. available values: 'unlimited', 0, or positive integer. default value: System defined value.
The Chroot directory at startup. the defined directory must be an absolute path. if it is not set, chroot is not used.
Set the Startup directory. the directory will be automatically Chdir to this directory during startup. the defined directory must be an absolute path. default value: current directory, or/Directory (when chroot is enabled ).
Redirects stdout and stderr in the running process to the main error log file. if not set, stdout and stderr will be redirected to/dev/null according to FastCGI rules. default value: null.
You can also pass additional environment variables for a runtime pool, or update the PHP configuration value. you can do it with the following configuration parameters in the php-fpm.conf:
Example #1 pass environment variables to the runtime pool and set PHP configuration values
Env [HOSTNAME] = $ HOSTNAME
Env [PATH] =/usr/local/bin:/usr/bin:/bin
Env [TMP] =/tmp
Env [TMPDIR] =/tmp
Env [TEMP] =/tmp
Php_admin_value [sendmail_path] =/usr/sbin/sendmail-t-I-f email@example.com
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] = 32 M
The PHP configuration value is set through php_value or php_flag and overwrites the previous value. please note that disable_functions or disable_classes is in php. the value defined in ini will not be overwritten, but the new settings will be appended to the original value.
The value defined by php_admin_value or php_admin_flag cannot be overwritten by ini_set () in PHP code.
Q: Can php-fpm be used with ZendOptimize?
Q: Can php-fpm be used with ZendPlatform, xcache, eAccelerator, APC, and other optimizers?
A: Yes. The php-fpm architecture and any shared memory used for high-speed opcode cache are applicable. The only restriction is that all worker processes can only apply to one cache, even if they run with different uid/gid
Q: Why should I patch php? This is not required for spawn-fcgi!
A: php-fpm is created to enhance management convenience. Php that has not been patched cannot:
Restart php smoothly without losing requests, including upgrading php binary files and/or extensions.
Run worker processes in different uid/gid/chroot environments
All settings have only one configuration file.
Dynamic request based on load (TODO)
Real-time statistics on the performance of php requests (TODO)
Q: Why should I use root to run php-fpm? Is this safe?
A: starting php-fpm with root makes sense only when you plan to use php with different uid/gid to process requests. For example, different sites on the shared host. This is because sub-processes with different uid/gid can be created only when the master process runs with root. This is quite safe. The master process never processes requests by itself.
Under no circumstances will php-fpm process requests as root.
Q: Can php-fpm accelerate the processing speed of php scripts?
A: No. it does not affect the processing speed. However, if you use some special features, you can still improve the performance of some specific requests.
Q: Will I improve performance if I migrate my website from mod_php to php-fpm?
A: Generally, when A server has A large amount of idle memory available, the performance improvement from migration to php-fpm may not be significant. However, if there is not enough memory, the performance improvement will be considerable. in some cases, it can reach 300-500%. This may be because nginx + php-fpm generally uses less memory than Apache + mod_php. In addition, the VFS cache will work more effectively due to more free memory.
Q: Will php-fpm be included by official php in the future?
A: I hope so. Currently, the protocol for php-fpm code is GPL. So the php-fpm code does not match the php protocol (similar to bsd. This is a temporary measure. This option is used to simplify the development process. Once the code has complete functions, such as Adaptive Generation of sub-processes and other things, the protocol will be changed to a matching one. Then, php-fpm will be officially released to the php development team and recommended for inclusion.