fix php startup errors when ini files contain environment variables (#2252)

closes #2250

---------

Signed-off-by: Marc <m@pyc.ac>
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
This commit is contained in:
Marc
2026-03-08 22:28:14 +07:00
committed by GitHub
parent a85faaeab8
commit 5979b4dac7
3 changed files with 22 additions and 11 deletions

View File

@@ -1135,6 +1135,13 @@ static void *php_main(void *arg) {
frankenphp_init_interned_strings();
/* take a snapshot of the environment for sandboxing */
if (main_thread_env == NULL) {
main_thread_env = pemalloc(sizeof(HashTable), 1);
zend_hash_init(main_thread_env, 8, NULL, NULL, 1);
go_init_os_env(main_thread_env);
}
frankenphp_sapi_module.startup(&frankenphp_sapi_module);
/* check if a default filter is set in php.ini and only filter if
@@ -1144,13 +1151,6 @@ static void *php_main(void *arg) {
should_filter_var = default_filter != NULL;
original_user_abort_setting = PG(ignore_user_abort);
/* take a snapshot of the environment for sandboxing */
if (main_thread_env == NULL) {
main_thread_env = pemalloc(sizeof(HashTable), 1);
zend_hash_init(main_thread_env, 8, NULL, NULL, 1);
go_init_os_env(main_thread_env);
}
go_frankenphp_main_thread_is_ready();
/* channel closed, shutdown gracefully */

View File

@@ -160,6 +160,19 @@ func testHelloWorld(t *testing.T, opts *testOptions) {
}, opts)
}
func TestEnvVarsInPhpIni(t *testing.T) {
t.Setenv("OPCACHE_ENABLE", "0")
runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, _ int) {
body, _ := testGet("http://example.com/ini.php?key=opcache.enable", handler, t)
assert.Equal(t, "opcache.enable:0", body)
}, &testOptions{
phpIni: map[string]string{
"opcache.enable": "${OPCACHE_ENABLE}",
},
})
}
func TestFinishRequest_module(t *testing.T) { testFinishRequest(t, nil) }
func TestFinishRequest_worker(t *testing.T) {
testFinishRequest(t, &testOptions{workerScript: "finish-request.php"})

View File

@@ -188,12 +188,11 @@ func TestReturnAnErrorIf2WorkersHaveTheSameFileName(t *testing.T) {
workersByName = map[string]*worker{}
workersByPath = map[string]*worker{}
w, err1 := newWorker(workerOpt{fileName: testDataPath + "/index.php"})
assert.NoError(t, err1)
workers = append(workers, w)
workersByName[w.name] = w
workersByPath[w.fileName] = w
_, err2 := newWorker(workerOpt{fileName: testDataPath + "/index.php"})
assert.NoError(t, err1)
assert.Error(t, err2, "two workers cannot have the same filename")
}
@@ -202,12 +201,11 @@ func TestReturnAnErrorIf2ModuleWorkersHaveTheSameName(t *testing.T) {
workersByName = map[string]*worker{}
workersByPath = map[string]*worker{}
w, err1 := newWorker(workerOpt{fileName: testDataPath + "/index.php", name: "workername"})
assert.NoError(t, err1)
workers = append(workers, w)
workersByName[w.name] = w
workersByPath[w.fileName] = w
_, err2 := newWorker(workerOpt{fileName: testDataPath + "/hello.php", name: "workername"})
assert.NoError(t, err1)
assert.Error(t, err2, "two workers cannot have the same name")
}