Skip to content

Commit 9381b46

Browse files
authored
FIX: Adjust php-fpm pool: enable the increase of maximum number of processes #190 (#191)
1 parent 6599e57 commit 9381b46

File tree

5 files changed

+66
-1
lines changed

5 files changed

+66
-1
lines changed

core/files/entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export FASTCGI_READ_TIMEOUT=${FASTCGI_READ_TIMEOUT:-300s}
4040
export FASTCGI_SEND_TIMEOUT=${FASTCGI_SEND_TIMEOUT:-300s}
4141
export FASTCGI_CONNECT_TIMEOUT=${FASTCGI_CONNECT_TIMEOUT:-300s}
4242

43+
export PHP_FCGI_CHILDREN=${PHP_FCGI_CHILDREN:-5}
44+
export PHP_FCGI_START_SERVERS=${PHP_FCGI_START_SERVERS:-2}
45+
export PHP_FCGI_SPARE_SERVERS=${PHP_FCGI_SPARE_SERVERS:-1}
46+
export PHP_FCGI_MAX_REQUESTS=${PHP_FCGI_MAX_REQUESTS:-0}
47+
4348
export PHP_MEMORY_LIMIT=${PHP_MEMORY_LIMIT:-2048M}
4449
export PHP_MAX_EXECUTION_TIME=${PHP_MAX_EXECUTION_TIME:-300}
4550
export PHP_UPLOAD_MAX_FILESIZE=${PHP_UPLOAD_MAX_FILESIZE:-50M}

core/files/entrypoint_fpm.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,35 @@ change_php_vars() {
2929
sed -i "s/session.sid_length = .*/session.sid_length = 64/" "$FILE"
3030
sed -i "s/session.use_strict_mode = .*/session.use_strict_mode = 1/" "$FILE"
3131
done
32+
33+
for FILE in /etc/php/*/fpm/pool.d/www.conf
34+
do
35+
[[ -e $FILE ]] || break
36+
echo "Configure PHP | Setting 'pm.max_children = ${PHP_FCGI_CHILDREN}'"
37+
sed -i -E "s/;?pm.max_children = .*/pm.max_children = ${PHP_FCGI_CHILDREN}/" "$FILE"
38+
echo "Configure PHP | Setting 'pm.start_servers = ${PHP_FCGI_START_SERVERS}'"
39+
sed -i -E "s/;?pm.start_servers = .*/pm.start_servers = ${PHP_FCGI_START_SERVERS}/" "$FILE"
40+
echo "Configure PHP | Setting 'pm.(min|max)_spare_servers = ${PHP_FCGI_START_SERVERS}'"
41+
sed -i -E "s/;?pm.min_spare_servers = .*/pm.min_spare_servers = ${PHP_FCGI_SPARE_SERVERS}/" "$FILE"
42+
if [[ "$PHP_FCGI_START_SERVERS" -gt "$PHP_FCGI_SPARE_SERVERS" ]]; then
43+
sed -i -E "s/;?pm.max_spare_servers = .*/pm.max_spare_servers = ${PHP_FCGI_START_SERVERS}/" "$FILE"
44+
else
45+
sed -i -E "s/;?pm.max_spare_servers = .*/pm.max_spare_servers = ${PHP_FCGI_SPARE_SERVERS}/" "$FILE"
46+
fi
47+
echo "Configure PHP | Setting 'pm.max_requests = ${PHP_FCGI_MAX_REQUESTS}'"
48+
sed -i -E "s/;?pm.max_requests = .*/pm.max_requests = ${PHP_FCGI_MAX_REQUESTS}/" "$FILE"
49+
if [[ "$FASTCGI_STATUS_LISTEN" != "" ]]; then
50+
echo "Configure PHP | Setting 'pm.status_path = /status'"
51+
sed -i -E "s/;?pm.status_path = .*/pm.status_path = \/status/" "$FILE"
52+
echo "Configure PHP | Setting 'pm.status_path = /run/php/php-fpm-status.sock'"
53+
sed -i -E "s/;?pm.status_listen = .*/pm.status_listen = \/run\/php\/php-fpm-status.sock/" "$FILE"
54+
else
55+
echo "Configure PHP | Disabling 'pm.status_path'"
56+
sed -i -E "s/^pm.status_path = /;pm.status_path = /" "$FILE"
57+
echo "Configure PHP | Disabling 'pm.status_listen'"
58+
sed -i -E "s/^pm.status_listen =/;pm.status_listen =/" "$FILE"
59+
fi
60+
done
3261
}
3362

3463
echo "Configure PHP | Change PHP values ..." && change_php_vars

core/files/entrypoint_nginx.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,15 @@ init_nginx() {
340340
echo "... DH parameters found"
341341
fi
342342
343+
if [[ "$FASTCGI_STATUS_LISTEN" != "" ]]; then
344+
echo "... enabling php-fpm status page"
345+
ln -s /etc/nginx/sites-available/php-fpm-status /etc/nginx/sites-enabled/php-fpm-status
346+
sed -i -E "s/ listen [^;]+/ listen $FASTCGI_STATUS_LISTEN" /etc/nginx/sites-enabled/php-fpm-status
347+
elif [[ -f /etc/nginx/sites-enabled/php-fpm-status ]]; then
348+
echo "... disabling php-fpm status page"
349+
rm /etc/nginx/sites-enabled/php-fpm-status
350+
fi
351+
343352
flip_nginx false false
344353
}
345354
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
server {
2+
listen 8999;
3+
location ~ ^/status$ {
4+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
5+
include fastcgi_params;
6+
fastcgi_pass unix:/run/php/php-fpm-status.sock;
7+
}
8+
}

template.env

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,13 @@ SYNCSERVERS_1_PULL_RULES=
179179
# 2 - Debug on + SQL dump
180180
# DEBUG=
181181

182-
# FastCGI configuration
182+
# FastCGI configuration on nginx
183183
# FASTCGI_READ_TIMEOUT=300s
184184
# FASTCGI_SEND_TIMEOUT=300s
185185
# FASTCGI_CONNECT_TIMEOUT=300s
186+
# Whete to listen to PHP-FPM status. Can be a port or a ip:port. If not set the status page will not be shown.
187+
# Do not expose this page in public networks.
188+
# FASTCGI_STATUS_LISTEN=""
186189

187190
# PHP FPM configuration
188191

@@ -198,6 +201,17 @@ SYNCSERVERS_1_PULL_RULES=
198201
# Maximum time PHP spends parsing input data in seconds.
199202
# PHP_MAX_INPUT_TIME=300
200203

204+
## PHP FPM pool setup
205+
# Maximum number of php-fpm processes, limits the number of simultaneous requests.
206+
PHP_FCGI_CHILDREN="5"
207+
# Number of processes created on startup.
208+
PHP_FCGI_START_SERVERS="2"
209+
# The desired number of idle server processes.
210+
PHP_FCGI_SPARE_SERVERS="1"
211+
# The number of requests each process should execute before respawning. "0" means endless request processing.
212+
PHP_FCGI_MAX_REQUESTS="0"
213+
214+
201215
## Additional PHP settings
202216
# Timeout (in minutes) for user session inactivity before it expires.
203217
# PHP_SESSION_TIMEOUT=60

0 commit comments

Comments
 (0)