From 6c057142a2bfdc8a444da1fdc0c9f5bb1a24974e Mon Sep 17 00:00:00 2001
From: Julian Rother <julian@cccv.de>
Date: Sun, 4 Dec 2022 01:06:25 +0100
Subject: [PATCH] Add nginx.php.fpm_process_count option

---
 README.md                     | 2 ++
 templates/php-fpm/www.conf.j2 | 6 +++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 8c1d5a7..a605126 100644
--- a/README.md
+++ b/README.md
@@ -151,6 +151,8 @@ data: {}
 
 **phpconfig**:
 ```
+# If set, fpm forks exactly the number of worker processes specified (pm=static, pm.max_children=COUNT)
+fpm_process_count: 5
 ini:
 	post_max_size: 64M
 	upload_max_filesize: 64M
diff --git a/templates/php-fpm/www.conf.j2 b/templates/php-fpm/www.conf.j2
index b9b3411..e16b2ce 100644
--- a/templates/php-fpm/www.conf.j2
+++ b/templates/php-fpm/www.conf.j2
@@ -99,7 +99,11 @@ listen.group = www-data
 ;             pm.process_idle_timeout   - The number of seconds after which
 ;                                         an idle process will be killed.
 ; Note: This value is mandatory.
+{% if nginx.php.fpm_process_count|d(False) %}
+pm = static
+{% else %}
 pm = dynamic
+{% endif %}
 
 ; The number of child processes to be created when pm is set to 'static' and the
 ; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
@@ -110,7 +114,7 @@ pm = dynamic
 ; forget to tweak pm.* to fit your needs.
 ; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
 ; Note: This value is mandatory.
-pm.max_children = 50
+pm.max_children = {{ nginx.php.fpm_process_count|d(50) }}
 
 ; The number of child processes created on startup.
 ; Note: Used only when pm is set to 'dynamic'
-- 
GitLab