From 6d7fcdb3a1d124385ed37ffdbb08c2af72aef8e0 Mon Sep 17 00:00:00 2001 From: Moritz Breitbach Date: Sun, 6 Sep 2026 21:01:09 +0200 Subject: [PATCH 1/2] Make pm.max_requests configurable Signed-off-by: Moritz Breitbach --- bin/ncp/CONFIG/nc-limits.sh | 14 ++++++++++---- etc/ncp-config.d/nc-limits.cfg | 7 +++++++ etc/ncp-templates/php/pool.d.www.conf.sh | 4 +++- updates/1.58.1.sh | 9 +++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 updates/1.58.1.sh diff --git a/bin/ncp/CONFIG/nc-limits.sh b/bin/ncp/CONFIG/nc-limits.sh index 40b2e76e6..7e60c5909 100644 --- a/bin/ncp/CONFIG/nc-limits.sh +++ b/bin/ncp/CONFIG/nc-limits.sh @@ -51,6 +51,12 @@ tmpl_php_threads() { echo -n "$PHPTHREADS" } +tmpl_php_maxrequests() { + local PHPMAXREQUESTS="$(find_app_param nc-limits PHPMAXREQUESTS)" + [[ $PHPMAXREQUESTS -eq 0 ]] && PHPMAXREQUESTS=500 + echo -n "$PHPMAXREQUESTS" +} + configure() { # Set auto memory limit to 75% of the total memory @@ -59,20 +65,20 @@ configure() file /bin/bash | grep 64-bit > /dev/null || TOTAL_MEM="$(( 1024 * 1024 * 1024 * 4 ))" local AUTOMEM=$(( TOTAL_MEM * 75 / 100 )) - # MAX FILESIZE - - # MAX PHP MEMORY +# MAX FILESIZE & MAX PHP MEMORY local require_fpm_restart=false local CONF=/etc/php/${PHPVER}/fpm/conf.d/90-ncp.ini local CONF_VALUE="$(cat "$CONF" 2> /dev/null || true)" + echo "Using $(tmpl_php_max_filesize) for PHP max filesize" echo "Using $(tmpl_php_max_memory) for PHP max memory" install_template "php/90-ncp.ini.sh" "$CONF" [[ "$CONF_VALUE" == "$(cat "$CONF")" ]] || require_fpm_restart=true - # MAX PHP THREADS + # MAX PHP THREADS & MAX REQUESTS local CONF=/etc/php/${PHPVER}/fpm/pool.d/www.conf CONF_VALUE="$(cat "$CONF" 2> /dev/null || true)" echo "Using $(tmpl_php_threads) PHP threads" + echo "Using $(tmpl_php_maxrequests) for PHP max requests" install_template "php/pool.d.www.conf.sh" "$CONF" [[ "$CONF_VALUE" == "$(cat "$CONF")" ]] || require_fpm_restart=true diff --git a/etc/ncp-config.d/nc-limits.cfg b/etc/ncp-config.d/nc-limits.cfg index 705d143b1..8f21b7479 100644 --- a/etc/ncp-config.d/nc-limits.cfg +++ b/etc/ncp-config.d/nc-limits.cfg @@ -27,6 +27,13 @@ "default": "0", "suggest": "0" }, + { + "id": "PHPMAXREQUESTS", + "name": "Max. requests before worker rotation", + "value": "500", + "default": "500", + "suggest": "500" + }, { "id": "REDISMEM", "name": "Redis memory", diff --git a/etc/ncp-templates/php/pool.d.www.conf.sh b/etc/ncp-templates/php/pool.d.www.conf.sh index c36173528..961835c1e 100644 --- a/etc/ncp-templates/php/pool.d.www.conf.sh +++ b/etc/ncp-templates/php/pool.d.www.conf.sh @@ -8,10 +8,11 @@ PHPVER="${PHPVER?ERROR: PHPVER variable unset!}" if [[ "$1" == "--defaults" ]] || ! [[ -f "${BINDIR}/CONFIG/nc-limits.sh" ]] then echo "INFO: Restoring template to default settings" >&2 - PHPTHREADS=16 + PHPMAXREQUESTS=500 else PHPTHREADS="$(source "${BINDIR}/CONFIG/nc-limits.sh"; tmpl_php_threads)" + PHPMAXREQUESTS="$(source "${BINDIR}/CONFIG/nc-limits.sh"; tmpl_php_maxrequests)" fi @@ -27,6 +28,7 @@ pm.max_children = ${PHPTHREADS} pm.start_servers = 4 pm.min_spare_servers = 4 pm.max_spare_servers = 8 +pm.max_requests = ${PHPMAXREQUESTS} pm.status_path = /status slowlog = log/\$pool.log.slow EOF diff --git a/updates/1.58.1.sh b/updates/1.58.1.sh new file mode 100644 index 000000000..98ecf05a6 --- /dev/null +++ b/updates/1.58.1.sh @@ -0,0 +1,9 @@ + #!/usr/bin/env bash + +set -euo pipefail + +source /usr/local/etc/library.sh + +install_template "php/pool.d.www.conf.sh" "/etc/php/${PHPVER}/fpm/pool.d/www.conf" + +systemctl daemon-reload From 2c74d21cf865cacc841008f60236fbf8e5825200 Mon Sep 17 00:00:00 2001 From: Moritz Breitbach Date: Sun, 6 Sep 2026 21:24:45 +0200 Subject: [PATCH 2/2] Translations for PHPMAXREQUESTS Signed-off-by: Moritz Breitbach --- bin/ncp/CONFIG/nc-limits.sh | 10 +++++----- etc/ncp-config.d/l10n/nc-limits/de.json | 13 ++++++++++--- etc/ncp-config.d/l10n/nc-limits/es.json | 1 + etc/ncp-config.d/l10n/nc-limits/pt.json | 1 + etc/ncp-config.d/l10n/nc-limits/ru.json | 10 +++++++++- etc/ncp-config.d/l10n/nc-limits/zh.json | 1 + etc/ncp-templates/php/pool.d.www.conf.sh | 2 +- 7 files changed, 28 insertions(+), 10 deletions(-) diff --git a/bin/ncp/CONFIG/nc-limits.sh b/bin/ncp/CONFIG/nc-limits.sh index 7e60c5909..f9f8073e6 100644 --- a/bin/ncp/CONFIG/nc-limits.sh +++ b/bin/ncp/CONFIG/nc-limits.sh @@ -48,10 +48,10 @@ tmpl_php_threads() { [[ $PHPTHREADS -eq 0 ]] && PHPTHREADS=$(( TOTAL_MEM / ( 100 * 1024 * 1024 ) )) # Minimum 16 [[ $PHPTHREADS -lt 16 ]] && PHPTHREADS=16 - echo -n "$PHPTHREADS" + echo -n "$PHPTHREADS" } -tmpl_php_maxrequests() { +tmpl_php_max_requests() { local PHPMAXREQUESTS="$(find_app_param nc-limits PHPMAXREQUESTS)" [[ $PHPMAXREQUESTS -eq 0 ]] && PHPMAXREQUESTS=500 echo -n "$PHPMAXREQUESTS" @@ -65,7 +65,7 @@ configure() file /bin/bash | grep 64-bit > /dev/null || TOTAL_MEM="$(( 1024 * 1024 * 1024 * 4 ))" local AUTOMEM=$(( TOTAL_MEM * 75 / 100 )) -# MAX FILESIZE & MAX PHP MEMORY +# PHP MAX FILESIZE & PHP MAX MEMORY local require_fpm_restart=false local CONF=/etc/php/${PHPVER}/fpm/conf.d/90-ncp.ini local CONF_VALUE="$(cat "$CONF" 2> /dev/null || true)" @@ -74,11 +74,11 @@ configure() install_template "php/90-ncp.ini.sh" "$CONF" [[ "$CONF_VALUE" == "$(cat "$CONF")" ]] || require_fpm_restart=true - # MAX PHP THREADS & MAX REQUESTS + # PHP THREADS & PHP MAX REQUESTS local CONF=/etc/php/${PHPVER}/fpm/pool.d/www.conf CONF_VALUE="$(cat "$CONF" 2> /dev/null || true)" echo "Using $(tmpl_php_threads) PHP threads" - echo "Using $(tmpl_php_maxrequests) for PHP max requests" + echo "Using $(tmpl_php_max_requests) for PHP max requests" install_template "php/pool.d.www.conf.sh" "$CONF" [[ "$CONF_VALUE" == "$(cat "$CONF")" ]] || require_fpm_restart=true diff --git a/etc/ncp-config.d/l10n/nc-limits/de.json b/etc/ncp-config.d/l10n/nc-limits/de.json index 705aefe4b..162261d5f 100644 --- a/etc/ncp-config.d/l10n/nc-limits/de.json +++ b/etc/ncp-config.d/l10n/nc-limits/de.json @@ -1,3 +1,10 @@ -{"translations": { - "nc-limits": "Systembegrenzungen" -}} \ No newline at end of file +{ + "translations": { + "nc-limits": "Systembegrenzungen", + "MAXFILESIZE": "Maximale Dateigröße", + "MEMORYLIMIT": "Speicherlimit", + "PHPTHREADS": "PHP-Threads", + "PHPMAXREQUESTS": "Max. Anfragen vor Worker-Rotation", + "REDISMEM": "Redis-Speicher" + } +} \ No newline at end of file diff --git a/etc/ncp-config.d/l10n/nc-limits/es.json b/etc/ncp-config.d/l10n/nc-limits/es.json index 15de20035..3b3fd7466 100644 --- a/etc/ncp-config.d/l10n/nc-limits/es.json +++ b/etc/ncp-config.d/l10n/nc-limits/es.json @@ -4,6 +4,7 @@ "MAXFILESIZE":"Tamaño máximo de archivo en subida", "MEMORYLIMIT": "Límite de memoria", "PHPTHREADS": "Hilos PHP", + "PHPMAXREQUESTS": "Máx. de solicitudes antes de rotar el worker", "REDISMEM": "Memoria Redis", "Set PHP threads to 0 in order to use all cores": "Configura los hilos a 0 para usar todos los cores", "nc-limits": "nc-limits" diff --git a/etc/ncp-config.d/l10n/nc-limits/pt.json b/etc/ncp-config.d/l10n/nc-limits/pt.json index 8fd28c590..0813edde0 100644 --- a/etc/ncp-config.d/l10n/nc-limits/pt.json +++ b/etc/ncp-config.d/l10n/nc-limits/pt.json @@ -4,6 +4,7 @@ "MAXFILESIZE":"Tamanho máximo de arquivo para upload", "MEMORYLIMIT": "Limite de memória", "PHPTHREADS": "THREADS PHP", + "PHPMAXREQUESTS": "Máx. de requisições antes da rotação do worker", "REDISMEM": "Memória Redis", "Set PHP threads to 0 in order to use all cores": "Configure as THREADS PHP à 0 para usar todas as cores", "nc-limits": "nc-limites" diff --git a/etc/ncp-config.d/l10n/nc-limits/ru.json b/etc/ncp-config.d/l10n/nc-limits/ru.json index 40bb9ed40..72d9a856c 100644 --- a/etc/ncp-config.d/l10n/nc-limits/ru.json +++ b/etc/ncp-config.d/l10n/nc-limits/ru.json @@ -1 +1,9 @@ -{"translations":{"MAXFILESIZE":"Максимальный размер файла","MEMORYLIMIT":"Ограничение памяти","PHPTHREADS":"PHP потоки","REDISMEM":"REDIS память"}} \ No newline at end of file +{ + "translations": { + "MAXFILESIZE": "Максимальный размер файла", + "MEMORYLIMIT": "Ограничение памяти", + "PHPTHREADS": "PHP потоки", + "PHPMAXREQUESTS": "Макс. запросов до ротации воркера", + "REDISMEM": "REDIS память" + } +} \ No newline at end of file diff --git a/etc/ncp-config.d/l10n/nc-limits/zh.json b/etc/ncp-config.d/l10n/nc-limits/zh.json index ae6a696d1..e453def6a 100644 --- a/etc/ncp-config.d/l10n/nc-limits/zh.json +++ b/etc/ncp-config.d/l10n/nc-limits/zh.json @@ -4,6 +4,7 @@ "MAXFILESIZE": "最大文件大小(<=2G)", "MEMORYLIMIT": "內存限制", "PHPTHREADS": "PHP線程", + "PHPMAXREQUESTS": "Worker 重启前的最大请求数", "REDISMEM": "REDIS記憶大小", "Examples: 200M or 2G. Write 0 for autoconfig": "例如:輸入200M或是2G。若要讓系統自行設定,請輸入0", "nc-limits": "修改NCP系統限制" diff --git a/etc/ncp-templates/php/pool.d.www.conf.sh b/etc/ncp-templates/php/pool.d.www.conf.sh index 961835c1e..1654eff1e 100644 --- a/etc/ncp-templates/php/pool.d.www.conf.sh +++ b/etc/ncp-templates/php/pool.d.www.conf.sh @@ -12,7 +12,7 @@ then PHPMAXREQUESTS=500 else PHPTHREADS="$(source "${BINDIR}/CONFIG/nc-limits.sh"; tmpl_php_threads)" - PHPMAXREQUESTS="$(source "${BINDIR}/CONFIG/nc-limits.sh"; tmpl_php_maxrequests)" + PHPMAXREQUESTS="$(source "${BINDIR}/CONFIG/nc-limits.sh"; tmpl_php_max_requests)" fi