Middle
What is PHP-FPM?
sobes.tech AI
Answer from AI
PHP-FPM (FastCGI Process Manager) is a FastCGI process manager for PHP, an alternative to the standard PHP FastCGI. It provides better performance when handling web requests in high-load environments. FPM manages a pool of PHP processes that wait for incoming requests from the web server (e.g., Nginx or Apache via the mod_proxy_fcgi module).
Key features and advantages of FPM:
- Process pool: FPM creates and manages a set of PHP processes. These processes can be static (fixed number), dynamic (created as needed within set limits), or on-demand (created upon request and destroyed after processing). This allows efficient use of system resources.
- Better scalability: By managing the process pool, FPM can handle many simultaneous requests, which is critical for high-load applications.
- Process separation: Each request is handled by a separate FPM process, increasing stability. A failure of one request does not affect others.
- Configuration: Allows flexible configuration of process behavior, such as maximum requests per process, process lifetime, and memory management.
- Integration with web servers: Easily integrates with popular web servers via the FastCGI protocol.
Example of a process pool configuration in php-fpm.d/www.conf:
; Pool name
[www]
; User and group under which processes will run
user = www-data
group = www-data
; Listening on TCP socket:
; listen = 127.0.0.1:9000
; ...or on Unix socket:
listen = /run/php/php7.4-fpm.sock
; Process management method:
; static - fixed number of processes (`pm.max_children`)
; dynamic - dynamic number of processes (`pm.start_servers`, `pm.min_servers`, `pm.max_servers`)
; ondemand - created upon request (`pm.process_idle_timeout`, `pm.max_children`)
pm = dynamic
; Initial number of child processes at startup in dynamic mode
pm.start_servers = 5
; Minimum number of child processes always running in dynamic mode
pm.min_servers = 2
; Maximum number of child processes in dynamic and static/ondemand modes
pm.max_children = 15
Without FPM, the web server would have to start the PHP interpreter for each PHP request, which is very inefficient due to overhead. FPM solves this problem by maintaining ready-to-use processes.