Skip to content

Instantly share code, notes, and snippets.

@aabed
Created December 18, 2023 15:42
Show Gist options
  • Save aabed/58302151de864998085e0879f9155edf to your computer and use it in GitHub Desktop.
Save aabed/58302151de864998085e0879f9155edf to your computer and use it in GitHub Desktop.
neqabty
In PHP-FPM (FastCGI Process Manager), the `pm.start_servers` directive is part of the pool configuration and determines the number of child server processes that should be created when PHP-FPM starts. PHP-FPM uses a process manager to handle incoming requests and distribute them among a pool of worker processes. The `pm.start_servers` setting specifically defines the number of child processes that should be created at the beginning to handle incoming requests.
Here's a breakdown of how `pm.start_servers` works:
1. **Startup**: When PHP-FPM starts, it needs to create a certain number of child processes to handle incoming requests. These child processes are responsible for executing PHP scripts.
2. **pm.start_servers**: This directive sets the number of child processes that should be created during the startup phase. For example, if `pm.start_servers` is set to 5, PHP-FPM will spawn 5 child processes when it starts.
3. **Balancing Load**: The total number of child processes created includes not only the `pm.start_servers` but also other types of processes, such as dynamic and on-demand processes (controlled by `pm.max_children`, `pm.min_spare_servers`, and `pm.max_spare_servers`). The combination of these settings helps manage the overall performance and resource usage of PHP-FPM.
4. **Adapting to Load**: After the initial startup, PHP-FPM dynamically adjusts the number of active child processes based on the incoming load. It can spawn additional child processes when the load increases and terminate some when the load decreases, helping to optimize resource utilization.
Here's a simple example of a PHP-FPM pool configuration file with `pm.start_servers` set:
```ini
; /etc/php-fpm.d/www.conf
[www]
listen = 127.0.0.1:9000
pm = dynamic
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pm.max_children = 50
```
In this example, `pm.start_servers` is set to 5, meaning that PHP-FPM will create 5 child processes during startup. The other directives (`pm.min_spare_servers`, `pm.max_spare_servers`, `pm.max_children`) work together to manage the pool size dynamically based on the load.
Adjusting these settings requires careful consideration of your server's resources and the expected traffic patterns for your PHP applications.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment