From 010fbd019e83c8e961887d019a09036bc8bc9b30 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 25 Sep 2025 14:52:41 +0200 Subject: [PATCH 1/3] fpm: add support for passing ini files to tester --- sapi/fpm/tests/tester.inc | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/sapi/fpm/tests/tester.inc b/sapi/fpm/tests/tester.inc index 9079886543378..9e15a4a477bcd 100644 --- a/sapi/fpm/tests/tester.inc +++ b/sapi/fpm/tests/tester.inc @@ -56,7 +56,7 @@ class Tester /** * @var array */ - static private array $filesToClean = ['.user.ini']; + static private array $filesToClean = ['.user.ini', 'php.ini']; /** * @var bool @@ -496,12 +496,12 @@ class Tester /** * Start PHP-FPM master process * - * @param array $extraArgs Command extra arguments. - * @param bool $forceStderr Whether to output to stderr so error log is used. - * @param bool $daemonize Whether to start FPM daemonized - * @param array $extensions List of extension to add if shared build used. - * @param array $iniEntries List of ini entries to use. - * @param array|null $envVars List of env variable to execute FPM with or null to use the current ones. + * @param array $extraArgs Command extra arguments. + * @param bool $forceStderr Whether to output to stderr so error log is used. + * @param bool $daemonize Whether to start FPM daemonized + * @param array $extensions List of extension to add if shared build used. + * @param array|string $iniEntries List of ini entries or content of php.ini to use. + * @param array|null $envVars List of env variable to execute FPM with or null to use the current ones. * * @return bool * @throws \Exception @@ -511,7 +511,7 @@ class Tester bool $forceStderr = true, bool $daemonize = false, array $extensions = [], - array $iniEntries = [], + array|string $iniEntries = [], ?array $envVars = null, ) { $configFile = $this->createConfig(); @@ -536,8 +536,15 @@ class Tester } } - foreach ($iniEntries as $iniEntryName => $iniEntryValue) { - $cmd[] = '-d' . $iniEntryName . '=' . $iniEntryValue; + if (is_string($iniEntries)) { + $iniFile = __DIR__ . '/php.ini'; + $this->trace('Writing php.ini file', $iniEntries, isFile: true); + file_put_contents($iniFile, $iniEntries); + $cmd[] = '-c' . $iniFile; + } else { + foreach ($iniEntries as $iniEntryName => $iniEntryValue) { + $cmd[] = '-d' . $iniEntryName . '=' . $iniEntryValue; + } } if ($envVars['TEST_FPM_RUN_AS_ROOT'] ?? getenv('TEST_FPM_RUN_AS_ROOT')) { From 40f37221e5b621ef132bdb8a01b50be625c44918 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 29 Sep 2025 13:01:40 +0200 Subject: [PATCH 2/3] Make sure to modify memory_limit value through the registered handler. --- Zend/zend_string.h | 1 + build/gen_stub.php | 1 + main/main.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Zend/zend_string.h b/Zend/zend_string.h index 87f221125202c..79be2db4322ef 100644 --- a/Zend/zend_string.h +++ b/Zend/zend_string.h @@ -636,6 +636,7 @@ EMPTY_SWITCH_DEFAULT_CASE() _(ZEND_STR_SINCE, "since") \ _(ZEND_STR_GET, "get") \ _(ZEND_STR_SET, "set") \ + _(ZEND_STR_MEMORY_LIMIT, "memory_limit") \ _(ZEND_STR_8_DOT_0, "8.0") \ _(ZEND_STR_8_DOT_1, "8.1") \ _(ZEND_STR_8_DOT_2, "8.2") \ diff --git a/build/gen_stub.php b/build/gen_stub.php index 8495f3612ce54..d20e18d5fbe6e 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -3029,6 +3029,7 @@ class StringBuilder { "username" => "ZEND_STR_USERNAME", "password" => "ZEND_STR_PASSWORD", "clone" => "ZEND_STR_CLONE", + "memory_limit" => "ZEND_STR_MEMORY_LIMIT", '8.0' => 'ZEND_STR_8_DOT_0', '8.1' => 'ZEND_STR_8_DOT_1', '8.2' => 'ZEND_STR_8_DOT_2', diff --git a/main/main.c b/main/main.c index e33ef29d61bb7..043e2bfb7ab13 100644 --- a/main/main.c +++ b/main/main.c @@ -381,8 +381,8 @@ static PHP_INI_MH(OnChangeMaxMemoryLimit) return FAILURE; } - PG(memory_limit) = value; PG(max_memory_limit) = value; + zend_alter_ini_entry(ZSTR_KNOWN(ZEND_STR_MEMORY_LIMIT), new_value, PHP_INI_ALL, stage); return SUCCESS; } From 3b5af633821c7645e9b3b3836cc8f801324ad9b5 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 29 Sep 2025 13:01:50 +0200 Subject: [PATCH 3/3] fpm: ini settings passed through fcgi env should be restored after the request has finished --- sapi/fpm/fpm/fpm_main.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index fa2417122e736..59f15357702d3 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -1396,7 +1396,6 @@ static void fastcgi_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback_ int *mode = (int *)arg; char *key; char *value = NULL; - struct key_value_s kv; if (!mode || !arg1) return; @@ -1421,10 +1420,7 @@ static void fastcgi_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback_ return; } - kv.key = key; - kv.value = value; - kv.next = NULL; - if (fpm_php_apply_defines_ex(&kv, *mode) == -1) { + if (zend_alter_ini_entry_chars(Z_STR_P(arg1), Z_STRVAL_P(arg2), Z_STRLEN_P(arg2), *mode, PHP_INI_STAGE_HTACCESS) == FAILURE) { zlog(ZLOG_ERROR, "Passing INI directive through FastCGI: unable to set '%s'", key); } }