FastCGI Process Manager (FPM)

Source: Internet
Author: User
Tags http 200

The FPM (FastCGI process Manager) replaces most of the additional features of PHP FastCGI and is useful for high-payload sites.

Its features include:

    • Advanced process management features that support smooth stop/start;

    • Can work in different uid/gid/chroot environments, and listen to different ports and use different php.ini configuration files (can replace Safe_mode settings);

    • StdOut and stderr log records;

    • Ability to restart and cache corrupted opcode in the event of an unexpected situation;

    • File upload optimization support;

    • Slow log-records scripts (not only the file name, but also the PHP backtrace information, which can be used to read and analyze the running data of the remote process using ptrace or similar tools), resulting in unusually slow operation;

    • Fastcgi_finish_request ()-Special function: To continue to perform time-consuming work in the background (input video conversion, statistical processing, etc.) after the request is completed and the data is refreshed;

    • Dynamic/static sub-process generation;

    • Basic SAPI operation status information (Apache-like mod_status);

    • PHP.ini-based configuration file.

Install from source code compilation

The --enable-fpm configuration option is required to activate FPM support when compiling PHP.

The following are the specific configuration parameters for FPM compilation (all optional parameters):

    • --with-fpm-user -Set the user identity of the FPM run (Default-nobody)

    • --with-fpm-group -Set the user group for the FPM runtime (Default-nobody)

    • --with-fpm-systemd -Enable SYSTEMD integration (Default-NO)

    • --with-fpm-acl -use POSIX access control list (Default-No) 5.6. Version 5 Valid

Configuration

The FPM configuration file is php-fpm.conf similar in syntax php.ini .

php-fpm.confGlobal Configuration Segment
pid string

The location of the PID file. The default is empty.

error_log string

The location of the error log. Default: The installation path #INSTALL_PREFIX #/log/php-fpm.log.

log_level string

The error level. The available levels are: alert (which must be processed immediately), error (Error condition), warning (warning condition), notice (general important information), debug (debug information). Default: Notice.

emergency_restart_threshold int

FPM restarts if the child process receives a SIGSEGV or Sigbus exit information number for that parameter setting within the time set by Emergency_restart_interval . 0 means "Turn off this feature." Default value: 0 (off).

emergency_restart_interval Mixed

The emergency_restart_interval is used to set the interval between smooth restarts. Doing so helps to solve the problem of using shared memory in the accelerator. Available units: s (seconds), M (min), H (Hours), or D (days). Default unit: s (seconds). Default value: 0 (off).

process_control_timeout Mixed

Sets the time-out period for the child process to accept the primary process multiplexing signal. Available units: s (seconds), M (min), H (Hours), or D (days). Default unit: s (seconds). Default value: 0 (off).

daemonize Boolean

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 individually for each process pool.

listen string

Sets the address that accepts the FastCGI request. The available formats are: ' Ip:port ', ' Port ', '/path/to/unix/socket '. Each process pool needs to be set.

listen.backlog int

Sets the half-connection queue length for listen (2). "-1" means no limit. Default value:-1.

listen.allowed_clients string

Sets the server IPV4 address that is allowed to connect to FastCGI. Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in PHP FastCGI (5.2.2+). Only works on TCP snooping. Each address is separated by commas and, if not set or empty, allows any server to request a connection. Default value: Any.

listen.owner string

If used, represents the permission to set Unix sockets. In Linux, read and write permissions must be set to be used for WEB server connections. In many BSD-derived systems, permissions can be ignored to allow free connections. Default value: The user and group to run, with a permission of 0666.

listen.group string

See Listen.owner.

listen.mode string

See Listen.owner.

user string

The FPM process runs as a UNIX user. Must be set.

group string

The FPM process runs the Unix user group. If not set, the default user's group is used.

pm string

Sets how the Process manager manages child processes. Available values:static,OnDemand,dynamic. Must be set.

Static -The number of child processes is fixed (pm.max_children).

OnDemand -The process is generated when there is a demand (as opposed to dynamic when requested,Pm.start_servers starts when the service starts.)

Dynamic-The number of child 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

The number of child processes created when pm is set to static indicates the maximum number of child processes that can be created when thePM is set to dynamic . Must be set.

This option sets a limit on the number of requests that can be served at the same time. Similar to the maxclients settings in Apache mpm_prefork and the environment variables in normal PHP fastcgi PHP_FCGI_CHILDREN .

pm.start_servers inch

Sets the number of child processes created at startup. Used only when the 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 the PM is set to dynamic . Must be set.

pm.max_spare_servers int

Sets the maximum number of idle service processes. Used only when the PM is set to dynamic . Must be set.

pm.max_requests int

Sets the number of requests for the service before each child process is reborn. is useful for third-party modules that may have a memory leak. If 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 status page cannot be accessed, the default value: 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 FPM is alive and can respond to requests. Note that you must start with a slash (/).

ping.response string

The return response used to define the ping request. Returns the Text/plain format text for HTTP 200. Default value: Pong.

request_terminate_timeout Mixed

Sets the time-out for a single request to abort. This option may be useful for scripts in php.ini settings where ' Max_execution_time ' is not aborted for some special reason. Set to ' 0 ' to indicate ' Off '. Available units: s (seconds), M (min), H (Hours), or D (days). Default unit: s (seconds). Default value: 0 (off).

request_slowlog_timeout Mixed

When a request for this setting time-out expires, the corresponding PHP call stack information is written to the slow log. Set to ' 0 ' to indicate ' Off '. Available units: s (seconds), M (min), H (Hours), or D (days). Default unit: s (seconds). Default value: 0 (off).

slowlog string

Logging of slow requests. Default value:#INSTALL_PREFIX #/log/php-fpm.log.slow.

rlimit_files int

Sets the Rlimit limit for the file open descriptor. Default value: System-defined value.

rlimit_core int

Sets the maximum limit value for the core rlimit. 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 not set, Chroot is not used.

chdir string

Sets the startup directory, which is automatically Chdir to the directory when it starts. The defined directory needs to be an absolute path. Default value: Current directory, or root directory (chroot).

catch_workers_output Boolean

REDIRECT StdOut and stderr to the primary error log file during the run. If not set, stdout and stderr will be redirected to/dev/null according to the FastCGI rules. Default value: None.

You can also pass additional environment variables for a running pool, or update the PHP configuration values. You can do this in the php-fpm.conf following configuration parameters:

Example #1 Pass environment variables and set PHP configuration values to the run pool

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 protected]       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 values are passed Php_valueOr Php_flagSettings, and overwrites the previous value. Please note that disable_functions or disable_classes isphp.iniThe values defined in are not overwritten, but the new settings are appended to the original values.

Values defined using php_admin_value or php_admin_flag cannot be overridden by Ini_set () in the PHP code.

PHP settings can also be set via the Web server from 5.3.3 onwards.

Example #2 set PHP in nginx.conf

Set $php _value "pcre.backtrack_limit=424242"; set $php _value "$php _value \ n pcre.recursion_limit=99999"; fastcgi_param  php_value $php _value;fastcgi_param  Php_admin_value "Open_basedir=/var/www/htdocs";
Caution

Since these settings are passed to FastCGI headers to PHP-FPM,PHP-FPM should not be bound to an address that can be accessed by the extranet, anyone can modify the configuration options for PHP. See listen.allowed_clients.

FastCGI Process Manager (FPM)

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.