Home > Backend Development > PHP7 > body text

Three little-known modes of FPM

醉折花枝作酒筹
Release: 2023-02-18 07:28:01
forward
2181 people have browsed it

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!

Related labels:
source:csdn.net
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