Table of Contents
static
dynamic
ondemand
FPM’s signal processing
Life cycle of FPM
Home Backend Development PHP7 Three little-known modes of FPM

Three little-known modes of FPM

Jul 21, 2021 am 09:39 AM
fpm php7

We often use php-fpm, but not everyone knows that fpm has three modes. Today Xiaonian will take you to understand the three modes of fpm. You can refer to it if you need it.

Three little-known modes of FPM

; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
;   dynamic - the number of child processes are set dynamically based on the
;             following directives. With this process management, there will be
;             always at least 1 children.
;             pm.max_children      - the maximum number of children that can
;                                    be alive at the same time.
;             pm.start_servers     - the number of children created on startup.
;             pm.min_spare_servers - the minimum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is less than this
;                                    number then some children will be created.
;             pm.max_spare_servers - the maximum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is greater than this
;                                    number then some children will be killed.
;  ondemand - no children are created at startup. Children will be forked when
;             new requests will connect. The following parameter are used:
;             pm.max_children           - the maximum number of children that
;                                         can be alive at the same time.
;             pm.process_idle_timeout   - The number of seconds after which
;                                         an idle process will be killed.
; Note: This value is mandatory.
Copy after login

pm has three modes: static, dynamic and ondemand

static

This method is relatively simple , at startup, the master forks out a corresponding number of worker processes according to the pm.max_children configuration, that is, the number of worker processes is fixed.

dynamic

Dynamic process management, first initialize a certain number of workers according to pm.start_servers when fpm starts.

During operation, if the master finds that the number of idle workers is lower than the number of pm.min_spare_servers configured (indicating that there are too many requests and the workers cannot handle them), it will fork the worker process, but the total number of workers cannot exceed pm.max_children.

If the master finds that the number of idle workers exceeds pm.max_spare_servers (indicating that there are too many idle workers), it will kill some workers to avoid taking up too many resources. The master controls the number of workers through these 4 values. .

ondemand

This method is generally rarely used. The worker process is not allocated at startup, and the master process is notified to fork the worker process after there is a request. The total number of workers does not exceed pm. max_children, the worker process will not exit immediately after the processing is completed, and will exit after the idle time exceeds pm.process_idle_timeout.

pm.max_children: The number of php-fpm processes opened in static mode.

pm.start_servers: The number of starting php-fpm processes in dynamic mode.

pm.min_spare_servers: The minimum number of php-fpm processes in dynamic mode.

pm.max_spare_servers: The maximum number of php-fpm processes in dynamic mode.

FPM’s signal processing

php-fpm reload

php-fpm stop

kill SIGUSR1 php-fpm Reuse the new file and complete the log cutting

kill SIGUSR2 php-fpm Restart the work process and reload the configuration file

Q1: After starting the php-fpm process and killing the php-fpm master process number, can the service continue? A: No (all php-fpm processes are shut down)

Q2: After starting the php-fpm process, kill -9 php-fpm master process number, can the service continue? A: Yes (only the master process is killed, the work process is still working)

Q2: After starting the php-fpm process, kill the php-fpm work process number, can the service continue? A: Yes (after the work process is killed, a new work process is started)

Life cycle of FPM

php_module_startup()

fcgi_accept_request()

php_request_startup()

fmp_request_executing()

php_execute_script ()

fpm_requset_end()

php_request_shutdown()

Because fpm is a resident process, so in php_request_shutdown()Then the cycle will start from fcgi_accept_request().

Recommended learning: php video tutorial

The above is the detailed content of Three little-known modes of FPM. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if the plug-in is installed in php7.0 but it still shows that it is not installed? What should I do if the plug-in is installed in php7.0 but it still shows that it is not installed? Apr 02, 2024 pm 07:39 PM

To resolve the plugin not showing installed issue in PHP 7.0: Check the plugin configuration and enable the plugin. Restart PHP to apply configuration changes. Check the plugin file permissions to make sure they are correct. Install missing dependencies to ensure the plugin functions properly. If all other steps fail, rebuild PHP. Other possible causes include incompatible plugin versions, loading the wrong version, or PHP configuration issues.

How to install mongo extension in php7.0 How to install mongo extension in php7.0 Nov 21, 2022 am 10:25 AM

How to install the mongo extension in php7.0: 1. Create the mongodb user group and user; 2. Download the mongodb source code package and place the source code package in the "/usr/local/src/" directory; 3. Enter "src/" directory; 4. Unzip the source code package; 5. Create the mongodb file directory; 6. Copy the files to the "mongodb/" directory; 7. Create the mongodb configuration file and modify the configuration.

How to solve the problem when php7 detects that the tcp port is not working How to solve the problem when php7 detects that the tcp port is not working Mar 22, 2023 am 09:30 AM

In php5, we can use the fsockopen() function to detect the TCP port. This function can be used to open a network connection and perform some network communication. But in php7, the fsockopen() function may encounter some problems, such as being unable to open the port, unable to connect to the server, etc. In order to solve this problem, we can use the socket_create() function and socket_connect() function to detect the TCP port.

PHP Server Environment FAQ Guide: Quickly Solve Common Problems PHP Server Environment FAQ Guide: Quickly Solve Common Problems Apr 09, 2024 pm 01:33 PM

Common solutions for PHP server environments include ensuring that the correct PHP version is installed and that relevant files have been copied to the module directory. Disable SELinux temporarily or permanently. Check and configure PHP.ini to ensure that necessary extensions have been added and set up correctly. Start or restart the PHP-FPM service. Check the DNS settings for resolution issues.

How to install and deploy php7.0 How to install and deploy php7.0 Nov 30, 2022 am 09:56 AM

How to install and deploy php7.0: 1. Go to the PHP official website to download the installation version corresponding to the local system; 2. Extract the downloaded zip file to the specified directory; 3. Open the command line window and go to the "E:\php7" directory Just run the "php -v" command.

Solve the problem of missing PHP-FPM in Ubuntu Solve the problem of missing PHP-FPM in Ubuntu Mar 08, 2024 pm 09:45 PM

To solve the problem of lack of PHP-FPM in Ubuntu, specific code examples are required. In the Ubuntu system, installing and configuring PHP-FPM is a common operation, but sometimes the problem of missing PHP-FPM occurs during the installation process. This article details how to solve this problem and provides specific code examples to help you complete the installation and configuration. 1. Check whether PHP-FPM has been installed. First, use the following command to check whether PHP-FPM has been installed in the system: dpkg-l|gr

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Apr 01, 2025 pm 03:06 PM

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

See all articles