search
HomeBackend DevelopmentPHP7Three little-known modes of FPM

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.

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
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete

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

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function