This article brings you a brief introduction to the operating principles and modes of php-fpm. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Operation principle:
cgi initialization phase: call the fcgi_init() and sapi_startup() functions respectively, register process signals and initialize the sapi_globals global variable.
php environment initialization phase: triggered by cgi_sapi_module.startup. The php_cgi_startup function is actually called, and php_cgi_startup internally calls php_module_startup for execution. The main functions of php_module_startup: a). Load and parse php configuration; b). Load php module and record it in the function symbol table (function_table); c). Load zend extension; d). Set disabled functions and class library configuration; e). Register the memory recovery method;
php-fpm initialization phase: execute the fpm_init() function. Responsible for parsing the php-fpm.conf file configuration, obtaining process-related parameters (the maximum number of files allowed to be opened by the process, etc.), initializing the process pool and event model and other operations.
php-fpm running phase: execute the fpm_run() function, and the main process will be blocked after running. This phase is divided into two parts: fork child process and loop event. The fork child process part is handled by the fpm_children_create_initial function (Note: ondemand mode is created in the fpm_pctl_on_socket_accept function). The loop event part is processed through the fpm_event_loop function, which is an infinite loop inside and is responsible for event collection.
Running mode
php-fpm supports three running modes, namely static, ondemand, and dynamic. The default is dynamic.
static: Static mode, a fixed worker process is allocated at startup.
ondemand: Allocate on demand, fork the worker process when a user request is received. ondemand: Allocate on demand, fork the worker process when a user request is received.
dynamic: Dynamic mode, a fixed process is allocated at startup. As the number of requests increases, adjust the worker process within the set floating range
The above is the detailed content of A brief introduction to the operating principles and modes of php-fpm. For more information, please follow other related articles on the PHP Chinese website!