An in-depth understanding _php example based on PHP-FPM parameters

Source: Internet
Author: User
Tags fpm http 200 memory usage mixed php script
PS aux |grep php-fpm |more
View Total 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
The error level. Available levels are: alert (must be processed immediately), error (Errors), warning (warning condition), notice (general important information), debug (debug information). Default: Notice.
Emergency_restart_threshold int
If the subprocess receives the SIGSEGV or Sigbus exit information number set by the Emergency_restart_interval within the time set by the child, FPM restarts. 0 means ' Turn off the feature '. Default value: 0 (off).
Emergency_restart_interval Mixed
Emergency_restart_interval is used to set the interval between smooth restarts. Doing so helps solve the problem of shared memory usage in the accelerator. Available units: s (seconds), M (minutes), H (Hours), or D (days). Default unit: S (sec). Default value: 0 (off).
Process_control_timeout Mixed
Sets the timeout for the child process to accept the main process multiplexing signal. Available units: s (seconds), M (minutes), H (Hours), or D (day) default units: S (sec). Default value: 0.
Daemonize Boolean
Set FPM to run in the background. Set ' no ' to keep FPM in the foreground to run 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 individually for each process pool.
Listen string
Sets the address that accepts the FASTCGI request. Available formats are: ' Ip:port ', ' Port ', '/path/to/unix/socket '. Each process pool needs to be set.
Listen.backlog int
Sets the listen queue length for the (2). ' -1′ says no limit. Default value:-1.
Listen.allowed_clients string
Sets the IPV4 address of the server that is allowed to connect to fastcgi. Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in PHP FastCGI (5.2.2+). Only TCP monitoring works. Each address is separated by commas. If it is not set or empty, any server is allowed to request a connection. Default value: Any.
Listen.owner string
If used, indicates the right to set up UNIX sockets. In Linux, read and write permissions must be set up to be used for Web server connections. In many BSD-derived systems, permissions allow free connections to be ignored. Default value: Runs the user to use the rent, the permission is 0666.
Listen.group string
See Listen.owner.
Listen.mode string
See Listen.owner.
User string
FPM the UNIX user who is running the process. Must be set.
Group string
The UNIX user group that the FPM process runs. If it is not set, the default user's group is used.
PM string
Sets how the Process manager manages child processes. Available values: static, dynamic. Must be set.
The number of static– subprocess is fixed (pm.max_children).
The number of dynamic– is dynamically set based on the configuration below: Pm.max_children, Pm.start_servers, Pm.min_spare_servers, Pm.max_spare_servers.
Pm.max_children int
The number of child processes, which is created when PM is set to static, and when PM is set to dynamic, it represents the maximum that can be created. Must be set.
This option sets the limit of the number of requests that can provide the service at the same time. Similar to the maxclients settings in Apache mpm_prefork and the Php_fcgi_children environment variables in normal PHP fastcgi.
Pm.start_servers in
Sets the number of child processes created at startup. Used only when PM is set to dynamic. Default value: Min_spare_servers + (Max_spare_servers–min_spare_servers)/2.
pm.min_spare_servers int
Sets the minimum number of idle service processes. Used only when PM is set to dynamic. Must be set.
pm.max_spare_servers int
Sets the maximum number of idle service processes. Used only when PM is set to dynamic. Must be set.
pm.max_requests int
Sets the number of requests for services before each subprocess is reborn. is useful for Third-party modules that may have memory leaks. If set to ' 0′, the request is always accepted. Equivalent to php_fcgi_max_requests environment variables. Default value: 0.
Pm.status_path string
The URL of the FPM status page. If it is not set, the status page cannot be accessed. Default value: None.
Ping.path string
FPM the ping site of the monitor page. If it is not set, the ping page cannot be accessed. This page is used to externally detect if FPM is alive and can respond to requests. Please note that you must start with a slash (/).
Ping.response string
Used to define the return corresponding to the ping request. Returns the Text/plain-formatted text for HTTP 200. Default value: Pong.
Request_terminate_timeout Mixed
Sets the time-out period for a single request. This option may be useful for the ' max_execution_time ' in the php.ini setting that does not abort the script for some special reason. Set to ' 0′ ' indicates ' off '. Available units:s (econds) (default), M (inutes), H (ours), or D (ays). Default value:0.
Request_slowlog_timeout Mixed
When a timeout is requested for this setting, the corresponding PHP call stack information is fully written to the slow log. Set to ' 0′ ' indicates ' off '. Available units: s (seconds) (default), M (minutes), H (Hours), or D (days). Default value: 0.
Slowlog string
Log logs for slow requests. Default value: #INSTALL_PREFIX #/log/php-fpm.log.slow.
Request_slowlog_timeout
Scope: php-fpm.conf Options
Category: Convenient
This option allows you to track the execution of slow scripts and log them along with the call stack. For example, the following settings are:
<value name= "Request_slowlog_timeout" >5s</value>
<value name= "Slowlog" >logs/slow.log</value>
The recorded slow.log may look like this:
Copy Code code as follows:

SEP 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 16:22:19.399031 [WARNING] fpm_request_check_timed_out (), line 135:child 29715, script '/local/www/stable/www/cat Alogue.php ' (pool default) executing too slow (5.018002 sec), logging
As you can see in the example, the script runs for more than 5 seconds and is most likely due to slow MySQL response (top backtrace).
Rlimit_files int
Sets the Rlimit limit for file open descriptors. 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
The Chroot directory at startup. The defined directory needs to be an absolute path. If it is not set, then chroot is not used.
ChDir string
Sets the startup directory, which is automatically chdir to the directory when it is started. The defined directory needs to be an absolute path. Default value: Current directory, or/directory (chroot).
Catch_workers_output Boolean
StdOut and stderr during the redirection run to the primary error log file. If there are no settings, stdout and stderr will be redirected to/dev/null according to the FASTCGI rules. Default value: null.
You can also pass additional environment variables for a running pool, or update the configuration values for PHP. You can do this with the following configuration parameters in php-fpm.conf:
Example #1 Pass environment variables to the runtime 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
The PHP configuration value is set by Php_value or Php_flag and overrides the previous value. Note that disable_functions or disable_classes values defined in php.ini will not be overwritten, but the new settings will be appended to the previous values.
Values defined with Php_admin_value or Php_admin_flag cannot be overwritten by Ini_set () in the PHP code.
FAQ
Can q:php-fpm be used with zendoptimize?
A: Perfectly OK.

Can q:php-fpm be used with the optimizer of Zendplatform, XCache, Eaccelerator, APC, etc.?
A: Yes. The PHP-FPM architecture and any one of the shared memory used for the high-speed opcode cache are applicable. The only limitation is that all worker processes can only be used for one cache, even if they run with a different uid/gid

Q: Why do I have to make a patch for PHP? SPAWN-FCGI don't need this!
A:PHP-FPM is created to enhance ease of management. PHP that has not patched is not possible:

Smooth reboot PHP without losing requests, including upgrading PHP binaries and/or extensions.
Run the worker process with a different uid/gid/chroot environment
All settings have only one configuration file
Dynamic request based on load (TODO)
Real-time statistical performance for PHP requests (TODO)

Q: Why do you run php-fpm with root? Is it safe?
A: Starting with root php-fpm only makes sense when you intend to handle requests with different uid/gid PHP. For example, a different site on a shared host. Because it is only when the master process runs with root, you can build different uid/gid of the child process. This is quite safe. The master process itself never handles requests.
In any case, PHP-FPM does not use root to process requests.

Can q:php-fpm speed up php script processing?
A: No, it doesn't affect the processing speed. However, if you use some special features, there can be performance improvements for certain requests.

Q: If I move my site from mod_php to PHP-FPM, will I get a performance boost?
A: Typically, when there is a large amount of free memory available on the server, the performance boost from migrating to PHP-FPM may not be significant. However, if the memory is not sufficient, performance improvement is very considerable, in some cases can be achieved 300-500%. This may be due to the fact that Nginx + PHP-FPM generally uses less memory than Apache + mod_php. And the VFS cache works more efficiently due to more free memory.

Will Q:PHP-FPM be included in the official PHP future?
A: I hope so. Currently, the protocol for PHP-FPM code is the GPL. So now the PHP-FPM code does not match the PHP protocol (like BSD). This is a temporary measure. The choice is to simplify the development process. Once the code is fully functional, such as an adaptive build subprocess and something else, the protocol changes to a match. After that, PHP-FPM is officially released to the PHP development team and is recommended for inclusion.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.