FIX: Adjust php-fpm pool: enable the increase of maximum number of processes #190 (#191)

pull/198/head
Guilherme Capilé 2024-12-06 11:30:32 -03:00 committed by GitHub
parent 6599e57297
commit 9381b463d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 66 additions and 1 deletions

View File

@ -40,6 +40,11 @@ export FASTCGI_READ_TIMEOUT=${FASTCGI_READ_TIMEOUT:-300s}
export FASTCGI_SEND_TIMEOUT=${FASTCGI_SEND_TIMEOUT:-300s}
export FASTCGI_CONNECT_TIMEOUT=${FASTCGI_CONNECT_TIMEOUT:-300s}
export PHP_FCGI_CHILDREN=${PHP_FCGI_CHILDREN:-5}
export PHP_FCGI_START_SERVERS=${PHP_FCGI_START_SERVERS:-2}
export PHP_FCGI_SPARE_SERVERS=${PHP_FCGI_SPARE_SERVERS:-1}
export PHP_FCGI_MAX_REQUESTS=${PHP_FCGI_MAX_REQUESTS:-0}
export PHP_MEMORY_LIMIT=${PHP_MEMORY_LIMIT:-2048M}
export PHP_MAX_EXECUTION_TIME=${PHP_MAX_EXECUTION_TIME:-300}
export PHP_UPLOAD_MAX_FILESIZE=${PHP_UPLOAD_MAX_FILESIZE:-50M}

View File

@ -29,6 +29,35 @@ change_php_vars() {
sed -i "s/session.sid_length = .*/session.sid_length = 64/" "$FILE"
sed -i "s/session.use_strict_mode = .*/session.use_strict_mode = 1/" "$FILE"
done
for FILE in /etc/php/*/fpm/pool.d/www.conf
do
[[ -e $FILE ]] || break
echo "Configure PHP | Setting 'pm.max_children = ${PHP_FCGI_CHILDREN}'"
sed -i -E "s/;?pm.max_children = .*/pm.max_children = ${PHP_FCGI_CHILDREN}/" "$FILE"
echo "Configure PHP | Setting 'pm.start_servers = ${PHP_FCGI_START_SERVERS}'"
sed -i -E "s/;?pm.start_servers = .*/pm.start_servers = ${PHP_FCGI_START_SERVERS}/" "$FILE"
echo "Configure PHP | Setting 'pm.(min|max)_spare_servers = ${PHP_FCGI_START_SERVERS}'"
sed -i -E "s/;?pm.min_spare_servers = .*/pm.min_spare_servers = ${PHP_FCGI_SPARE_SERVERS}/" "$FILE"
if [[ "$PHP_FCGI_START_SERVERS" -gt "$PHP_FCGI_SPARE_SERVERS" ]]; then
sed -i -E "s/;?pm.max_spare_servers = .*/pm.max_spare_servers = ${PHP_FCGI_START_SERVERS}/" "$FILE"
else
sed -i -E "s/;?pm.max_spare_servers = .*/pm.max_spare_servers = ${PHP_FCGI_SPARE_SERVERS}/" "$FILE"
fi
echo "Configure PHP | Setting 'pm.max_requests = ${PHP_FCGI_MAX_REQUESTS}'"
sed -i -E "s/;?pm.max_requests = .*/pm.max_requests = ${PHP_FCGI_MAX_REQUESTS}/" "$FILE"
if [[ "$FASTCGI_STATUS_LISTEN" != "" ]]; then
echo "Configure PHP | Setting 'pm.status_path = /status'"
sed -i -E "s/;?pm.status_path = .*/pm.status_path = \/status/" "$FILE"
echo "Configure PHP | Setting 'pm.status_path = /run/php/php-fpm-status.sock'"
sed -i -E "s/;?pm.status_listen = .*/pm.status_listen = \/run\/php\/php-fpm-status.sock/" "$FILE"
else
echo "Configure PHP | Disabling 'pm.status_path'"
sed -i -E "s/^pm.status_path = /;pm.status_path = /" "$FILE"
echo "Configure PHP | Disabling 'pm.status_listen'"
sed -i -E "s/^pm.status_listen =/;pm.status_listen =/" "$FILE"
fi
done
}
echo "Configure PHP | Change PHP values ..." && change_php_vars

View File

@ -340,6 +340,15 @@ init_nginx() {
echo "... DH parameters found"
fi
if [[ "$FASTCGI_STATUS_LISTEN" != "" ]]; then
echo "... enabling php-fpm status page"
ln -s /etc/nginx/sites-available/php-fpm-status /etc/nginx/sites-enabled/php-fpm-status
sed -i -E "s/ listen [^;]+/ listen $FASTCGI_STATUS_LISTEN" /etc/nginx/sites-enabled/php-fpm-status
elif [[ -f /etc/nginx/sites-enabled/php-fpm-status ]]; then
echo "... disabling php-fpm status page"
rm /etc/nginx/sites-enabled/php-fpm-status
fi
flip_nginx false false
}

View File

@ -0,0 +1,8 @@
server {
listen 8999;
location ~ ^/status$ {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass unix:/run/php/php-fpm-status.sock;
}
}

View File

@ -179,10 +179,13 @@ SYNCSERVERS_1_PULL_RULES=
# 2 - Debug on + SQL dump
# DEBUG=
# FastCGI configuration
# FastCGI configuration on nginx
# FASTCGI_READ_TIMEOUT=300s
# FASTCGI_SEND_TIMEOUT=300s
# FASTCGI_CONNECT_TIMEOUT=300s
# 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.
# Do not expose this page in public networks.
# FASTCGI_STATUS_LISTEN=""
# PHP FPM configuration
@ -198,6 +201,17 @@ SYNCSERVERS_1_PULL_RULES=
# Maximum time PHP spends parsing input data in seconds.
# PHP_MAX_INPUT_TIME=300
## PHP FPM pool setup
# Maximum number of php-fpm processes, limits the number of simultaneous requests.
PHP_FCGI_CHILDREN="5"
# Number of processes created on startup.
PHP_FCGI_START_SERVERS="2"
# The desired number of idle server processes.
PHP_FCGI_SPARE_SERVERS="1"
# The number of requests each process should execute before respawning. "0" means endless request processing.
PHP_FCGI_MAX_REQUESTS="0"
## Additional PHP settings
# Timeout (in minutes) for user session inactivity before it expires.
# PHP_SESSION_TIMEOUT=60