Home > Backend Development > PHP Tutorial > In-depth understanding of php-fpm parameters_PHP tutorial

In-depth understanding of php-fpm parameters_PHP tutorial

WBOY
Release: 2016-07-21 15:09:45
Original
773 people have browsed it

ps aux |grep php-fpm |more
View the total number of php-fpm
php-fpm.conf configuration
pid string
The location of the PID file. The default is empty.
error_log string
The location of the error log. Default: Installation path #INSTALL_PREFIX#/log/php-fpm.log.
log_level string
Error level. Available levels are: alert (must be processed immediately), error (error situation), warning (warning situation), notice (general important information), debug (debugging information). Default: notice.
emergency_restart_threshold int
If the child process receives this message within the time set by emergency_restart_interval If the number of SIGSEGV or SIGBUS exit messages set by the parameter is exceeded, FPM will restart. 0 means 'turn off this function'. Default value: 0 (off).
emergency_restart_interval mixed
emergency_restart_interval is used to set the smooth restart interval. Doing so 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).
process_control_timeout mixed
Set the child process Timeout for accepting multiplexed signals from the main process. Available units: s (seconds), m (minutes), h (hours), or d (days) Default unit: s (seconds). Default value: 0.
daemonize boolean
Set FPM to run in the background. Set 'no' to keep FPM running in the foreground for debugging. Default: yes.
Run configuration section
In FPM, you can run it with different settings Multiple process pools. These settings can be set individually for each process pool.
listen string
Set the address that accepts FastCGI requests. Available formats are: 'ip:port', 'port', '/path/to/unix/socket'. Each process pool needs to be set.
listen.backlog int
Set the semi-connection queue length of listen(2). '-1' means unlimited. Default value: -1.
listen.allowed_clients string
Set the server that is allowed to connect to FastCGI IPV4 address. Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in PHP FastCGI (5.2.2+). Only affects TCP listening. Each address is separated by a comma. If not set or empty, any server request connection is allowed. Default value : any.
listen.owner string
If used, indicates the permissions to set the Unix socket. In Linux, read and write permissions must be set in order to be used for WEB server connections. In many BSD-derived systems, this can Ignore permissions and allow free connections. Default: Run as the user sharing, permissions are 0666.
listen.group string
See listen.owner.
listen.mode string
See listen.owner.
user string
Unix user under which the FPM process runs. Must be set.
group string
Unix user group under which the FPM process runs. If not set, the default user's group is used.
pm string
Set how the process manager manages child processes. Available values: static, dynamic. Must be set.
static – the number of child processes is fixed (pm.max_children).
dynamic – the number of child processes 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
The number of child processes. When pm is set to static, it means that it is created. pm When set to dynamic, it indicates the maximum that can be created. It must be set.
This option sets the limit on the number of requests that can be served simultaneously. Similar to the setting of MaxClients in Apache's mpm_prefork and the PHP_FCGI_CHILDREN environment variable in ordinary PHP FastCGI.
pm .start_servers in
Set the number of child processes created at startup. 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 idle service The minimum number of processes. Only used when pm is set to dynamic. Must be set.
pm.max_spare_servers int
Sets the maximum number of idle service processes. Only used when pm is set to dynamic. Must be set.
pm.max_requests int
Set the number of requests served before each child process is reborn. This is very useful for third-party modules that may have memory leaks. If set to '0', requests will always be accepted. Equivalent to the PHP_FCGI_MAX_REQUESTS environment variable . Default value: 0.
pm.status_path string
URL of the FPM status page. If not set, the status page cannot be accessed. Default value: none.
ping.path string
FPM monitoring page The ping URL. If 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 start with a slash (/).
ping.response string
Use Used to define the response of the ping request. Returns the text/plain format text of HTTP 200. Default value: pong.
request_terminate_timeout mixed
Set the timeout abort time of a single request. This option may be set in php.ini The 'max_execution_time' is not useful for aborting running scripts for some special reasons. Set to '0' for 'Off'. Available units: s(econds)(default), m(inutes), h(ours), or d( ays). Default value: 0.
request_slowlog_timeout mixed
When a request is set for the timeout period, the corresponding PHP call stack information will be completely written to the slow log. Setting it to '0' means ' Off'. Available units: s (seconds) (default), m (minutes), h (hours), or d (days). Default value: 0.
slowlog string
Slow request log. Default Value: #INSTALL_PREFIX#/log/php-fpm.log.slow.
request_slowlog_timeout
Scope: php-fpm.conf Option
Category: Convenient
This option allows you to track slow scripts And record them together with the call stack in the log file. For example, the following setting:
5s
logs/slow.log
Slow recorded The .log may look like this:

Copy the code 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 ran for more than 5 seconds, and it was probably caused by the slow response of mysql (top backtrace).
rlimit_files int
Set the rlimit limit of the file open descriptor. Default value: system-defined value.
rlimit_core int
Set the core rlimit maximum limit value. Available values: 'unlimited', 0 or positive integer . Default value: System defined value.
chroot string
Chroot directory at startup. The defined directory needs to be an absolute path. If not set, chroot will not be used.
chdir string
Set Startup directory, which will be automatically Chdired to during startup. The defined directory needs to be an absolute path. Default value: current directory, or /directory (when chrooting).
catch_workers_output boolean
Redirect stdout during running and stderr to the main error log file. If not set, stdout and stderr will be redirected to /dev/null according to FastCGI's rules. Default value: empty.
You can also pass additional environment variables, or update PHP configuration values. You can do this by setting the following configuration parameters in php-fpm.conf:
Example #1 Pass environment variables to the run 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 www@my.domain.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] = 32M
PHP configuration value is set through php_value or php_flag, and will overwrite the previous one The value. Please note that the value defined in php.ini for disable_functions or disable_classes will not be overwritten, but the new setting will be appended to the original value.
The value defined using php_admin_value or php_admin_flag cannot be used by PHP ini_set() coverage in the code.
FAQ
Q: Can php-fpm be used with ZendOptimize?
A: Absolutely.

Q: Can php-fpm be used with optimizers such as ZendPlatform, xcache, eAccelerator, APC, etc.?
A: Yes. The architecture of php-fpm works with any kind of shared memory for high-speed opcode caching. The only restriction is: only one cache can be used for all worker processes, even if they run with different uids/gids

Q: Why should I patch php? spawn-fcgi doesn't need this!
A: php-fpm was created to enhance ease of management. Unpatched php can't do this:

Gracefully restart php without losing requests, including upgrading php binaries and/or extensions.
Run worker processes with different uid/gid/chroot environments
All settings have only one configuration file
Dynamic requests based on load (TODO)
Real-time statistical performance of php requests (TODO)

Q: Why do you need to use root to run php-fpm? Is this safe?
A: Starting php-fpm as root only makes sense if you plan to use php with different uid/gid to handle requests. For example, different sites on shared hosting. Because only when the master process is run as root, child processes with different uids/gids can be created. It's quite safe. The master process itself never handles requests.
Under no circumstances will php-fpm handle requests as root.

Q: Can php-fpm speed up php script processing?
A: No, it does not affect processing speed. However, if you use some special features, you can still improve performance for some specific requests.

Q: If I migrate my website from mod_php to php-fpm, will I get a performance improvement?
A: Typically, when there is a lot of free memory available on the server, the performance gain from migrating to php-fpm may not be large. But if memory is not abundant, the performance improvement is still considerable, reaching 300-500% in some cases. This may be due to the fact that nginx + php-fpm generally uses less memory than Apache + mod_php. And the VFS cache will work more efficiently due to more free memory.

Q: Will php-fpm be included in official php in the future?
A: I hope so. Currently, the php-fpm code is licensed under the GPL. So now the code of php-fpm does not match the php protocol (similar to bsd). This is a temporary measure. This choice is made to simplify the development process. Once the code is fully functional, such as adaptively spawning child processes and a few other things, the protocol will be changed to one that matches. Afterwards, php-fpm will be officially released to the PHP development team and recommended for inclusion.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327199.htmlTechArticleps aux |grep php-fpm |more View the total number of php-fpm php-fpm.conf Configure pid string PID file The location. The default is empty. error_log string The location of the error log. Default: Installation path #INSTA...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template