From 7fa782f5c632dde3b349019d882423bc93f31ff0 Mon Sep 17 00:00:00 2001 From: Karsten Dambekalns Date: Tue, 30 Jun 2026 21:16:32 +0200 Subject: [PATCH] Add PHP_FPM_REQUEST_TERMINATE_TIMEOUT setting Allow forcibly terminating requests after a wall-clock timeout, useful for requests stuck on I/O that max_execution_time does not catch. Defaults to 0 (disabled). --- README.md | 67 ++++++++++--------- root-files/opt/flownative/lib/php-fpm.sh | 1 + .../flownative/php/etc/php-fpm.conf.template | 2 + 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 7648ddf..dc7bbd1 100644 --- a/README.md +++ b/README.md @@ -63,39 +63,40 @@ similar mechanism in Kubernetes or your actual platform. ### Environment variables -| Variable Name | Type | Default | Description | -|---------------------------------|---------|----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------| -| PHP_BASE_PATH | string | /opt/flownative/php | Base path for PHP (read-only) | -| PHP_DATE_TIMEZONE | string | UTC | Default timezone ([doc](https://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone)) | -| PHP_ERROR_REPORTING | string | 2147483647 | PHP error reporting log levels ([doc](https://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting)) | -| PHP_DISPLAY_ERRORS | string | off | Display PHP errors ([doc](https://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors)) | -| PHP_ERROR_LOG | string | /dev/stderr | Path leading to the file where PHP errors should be logged | -| PHP_FPM_ERROR_LOG_PATH | string | /opt/flownative/log/php-fpm-error.log | Path leading to the file where PHP-FPM errors should be logged | -| PHP_FPM_ACCESS_LOG_PATH | string | /opt/flownative/log/php-fpm-access.log | Path leading to the file where PHP-FPM access should be logged | -| PHP_MEMORY_LIMIT | string | 750M | PHP memory limit ([doc](https://www.php.net/manual/en/ini.core.php#ini.memory-limit)) | -| PHP_OPCACHE_PRELOAD | string | | Path and filename of a preload script ([doc](https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.preload)) | -| PHP_XDEBUG_ENABLE | boolean | false | Enable or disable the Xdebug extension | -| PHP_XDEBUG_MODE | string | develop | Controls which Xdebug features are enabled, for example "develop" or "debug". See Xdebug manual for details | -| PHP_XDEBUG_CONFIG | string | | Values assigned to this variable are propagated as XDEBUG_CONFIG. See Xdebug manual for details | -| PHP_XDEBUG_DISCOVER_CLIENT_HOST | boolean | false | If enabled, Xdebug will first try to connect to the client that made the HTTP request. See Xdebug manual for details | -| PHP_XDEBUG_CLIENT_HOST | string | | Configures the IP address or hostname where Xdebug will attempt to connect to when initiating a debugging connection. See Xdebug manual for details | -| PHP_XDEBUG_MAX_NESTING_LEVEL | integer | 512 | Controls the protection mechanism for infinite recursion protection. See Xdebug manual for details | -| PHP_IGBINARY_ENABLE | boolean | false | Enable or disable the igbinary extension | -| PHP_EXCIMER_ENABLE | boolean | false | Enable or disable the Excimer extension | -| PHP_FPM_USER | string | 1000 | User id for running PHP (read-only) | -| PHP_FPM_GROUP | string | 1000 | Group id for running PHP (read-only) | -| PHP_FPM_PORT | string | 9000 | Port the PHP-FPM process listens to | -| PHP_FPM_MAX_CHILDREN | string | 20 | Maximum number of children to run | -| PHP_FPM_MAX_REQUESTS | string | 500 | Number of requests after which a worker is recycled to mitigate memory leaks; set to 0 to disable | -| PHP_FPM_REQUEST_SLOWLOG_TIMEOUT | string | 0 | Log requests (and count them on the FPM status page) that take longer than this, e.g. "5s"; set to 0 to disable | -| PHP_FPM_SLOWLOG_PATH | string | /opt/flownative/log/php-fpm-slow.log | Destination file for slowlog backtraces, used when PHP_FPM_REQUEST_SLOWLOG_TIMEOUT is enabled | -| PHP_FPM_PM_MODE | string | ondemand | Process manager mode for PHP-FPM; "static", "ondemand" or "dynamic" | -| PHP_SPX_ENABLE | boolean | false | Enable or disable the SPX extension | -| PHP_SPX_KEY | string | dev | The secret key used for authentication | -| PHP_SPX_IP_WHITELIST | string | | The IP address white list used for authentication as a comma separated list of IP addresses† | -| PHP_SPX_IP_VAR | string | REMOTE_ADDR | The $_SERVER key holding the client IP address used for authentication | -| PHP_SPX_TRUSTED_PROXIES | string | 127.0.0.1 | The trusted proxy list as a comma separated list of IP addresses†, ingored when `PHP_SPX_IP_VAR`is `REMOTE_ADDR` | -| | | | | +| Variable Name | Type | Default | Description | +|-----------------------------------|---------|----------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------| +| PHP_BASE_PATH | string | /opt/flownative/php | Base path for PHP (read-only) | +| PHP_DATE_TIMEZONE | string | UTC | Default timezone ([doc](https://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone)) | +| PHP_ERROR_REPORTING | string | 2147483647 | PHP error reporting log levels ([doc](https://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting)) | +| PHP_DISPLAY_ERRORS | string | off | Display PHP errors ([doc](https://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors)) | +| PHP_ERROR_LOG | string | /dev/stderr | Path leading to the file where PHP errors should be logged | +| PHP_FPM_ERROR_LOG_PATH | string | /opt/flownative/log/php-fpm-error.log | Path leading to the file where PHP-FPM errors should be logged | +| PHP_FPM_ACCESS_LOG_PATH | string | /opt/flownative/log/php-fpm-access.log | Path leading to the file where PHP-FPM access should be logged | +| PHP_MEMORY_LIMIT | string | 750M | PHP memory limit ([doc](https://www.php.net/manual/en/ini.core.php#ini.memory-limit)) | +| PHP_OPCACHE_PRELOAD | string | | Path and filename of a preload script ([doc](https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.preload)) | +| PHP_XDEBUG_ENABLE | boolean | false | Enable or disable the Xdebug extension | +| PHP_XDEBUG_MODE | string | develop | Controls which Xdebug features are enabled, for example "develop" or "debug". See Xdebug manual for details | +| PHP_XDEBUG_CONFIG | string | | Values assigned to this variable are propagated as XDEBUG_CONFIG. See Xdebug manual for details | +| PHP_XDEBUG_DISCOVER_CLIENT_HOST | boolean | false | If enabled, Xdebug will first try to connect to the client that made the HTTP request. See Xdebug manual for details | +| PHP_XDEBUG_CLIENT_HOST | string | | Configures the IP address or hostname where Xdebug will attempt to connect to when initiating a debugging connection. See Xdebug manual for details | +| PHP_XDEBUG_MAX_NESTING_LEVEL | integer | 512 | Controls the protection mechanism for infinite recursion protection. See Xdebug manual for details | +| PHP_IGBINARY_ENABLE | boolean | false | Enable or disable the igbinary extension | +| PHP_EXCIMER_ENABLE | boolean | false | Enable or disable the Excimer extension | +| PHP_FPM_USER | string | 1000 | User id for running PHP (read-only) | +| PHP_FPM_GROUP | string | 1000 | Group id for running PHP (read-only) | +| PHP_FPM_PORT | string | 9000 | Port the PHP-FPM process listens to | +| PHP_FPM_MAX_CHILDREN | string | 20 | Maximum number of children to run | +| PHP_FPM_MAX_REQUESTS | string | 500 | Number of requests after which a worker is recycled to mitigate memory leaks; set to 0 to disable | +| PHP_FPM_REQUEST_TERMINATE_TIMEOUT | string | 0 | Wall-clock time after which a request is forcibly terminated, e.g. "300s"; for requests stuck on I/O that `max_execution_time` misses; set to 0 to disable | +| PHP_FPM_REQUEST_SLOWLOG_TIMEOUT | string | 0 | Log requests (and count them on the FPM status page) that take longer than this, e.g. "5s"; set to 0 to disable | +| PHP_FPM_SLOWLOG_PATH | string | /opt/flownative/log/php-fpm-slow.log | Destination file for slowlog backtraces, used when PHP_FPM_REQUEST_SLOWLOG_TIMEOUT is enabled | +| PHP_FPM_PM_MODE | string | ondemand | Process manager mode for PHP-FPM; "static", "ondemand" or "dynamic" | +| PHP_SPX_ENABLE | boolean | false | Enable or disable the SPX extension | +| PHP_SPX_KEY | string | dev | The secret key used for authentication | +| PHP_SPX_IP_WHITELIST | string | | The IP address white list used for authentication as a comma separated list of IP addresses† | +| PHP_SPX_IP_VAR | string | REMOTE_ADDR | The $_SERVER key holding the client IP address used for authentication | +| PHP_SPX_TRUSTED_PROXIES | string | 127.0.0.1 | The trusted proxy list as a comma separated list of IP addresses†, ingored when `PHP_SPX_IP_VAR`is `REMOTE_ADDR` | +| | | | | † – `*` (match all) and subnet masks (e.g. `192.168.1.0/24`) are supported. diff --git a/root-files/opt/flownative/lib/php-fpm.sh b/root-files/opt/flownative/lib/php-fpm.sh index 9688417..3731d82 100755 --- a/root-files/opt/flownative/lib/php-fpm.sh +++ b/root-files/opt/flownative/lib/php-fpm.sh @@ -53,6 +53,7 @@ export PHP_FPM_PORT="${PHP_FPM_PORT:-9000}" export PHP_FPM_PM_MODE="${PHP_FPM_PM_MODE:-ondemand}" export PHP_FPM_MAX_CHILDREN="${PHP_FPM_MAX_CHILDREN:-20}" export PHP_FPM_MAX_REQUESTS="${PHP_FPM_MAX_REQUESTS:-500}" +export PHP_FPM_REQUEST_TERMINATE_TIMEOUT="${PHP_FPM_REQUEST_TERMINATE_TIMEOUT:-0}" export PHP_FPM_REQUEST_SLOWLOG_TIMEOUT="${PHP_FPM_REQUEST_SLOWLOG_TIMEOUT:-0}" export PHP_FPM_ERROR_LOG_PATH="${PHP_FPM_ERROR_LOG_PATH:-/opt/flownative/log/php-fpm-error.log}" export PHP_FPM_ACCESS_LOG_PATH="${PHP_FPM_ACCESS_LOG_PATH:-/opt/flownative/log/php-fpm-access.log}" diff --git a/root-files/opt/flownative/php/etc/php-fpm.conf.template b/root-files/opt/flownative/php/etc/php-fpm.conf.template index 8c9b791..c7924d8 100644 --- a/root-files/opt/flownative/php/etc/php-fpm.conf.template +++ b/root-files/opt/flownative/php/etc/php-fpm.conf.template @@ -22,6 +22,8 @@ pm = ${PHP_FPM_PM_MODE} pm.max_children = ${PHP_FPM_MAX_CHILDREN} pm.max_requests = ${PHP_FPM_MAX_REQUESTS} +request_terminate_timeout = ${PHP_FPM_REQUEST_TERMINATE_TIMEOUT} + slowlog = ${PHP_FPM_SLOWLOG_PATH} request_slowlog_timeout = ${PHP_FPM_REQUEST_SLOWLOG_TIMEOUT}