mirror of
https://github.com/php/frankenphp.git
synced 2026-03-24 00:52:11 +01:00
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:
14
frankenphp.c
14
frankenphp.c
@@ -1135,6 +1135,13 @@ static void *php_main(void *arg) {
|
|||||||
|
|
||||||
frankenphp_init_interned_strings();
|
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);
|
frankenphp_sapi_module.startup(&frankenphp_sapi_module);
|
||||||
|
|
||||||
/* check if a default filter is set in php.ini and only filter if
|
/* 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;
|
should_filter_var = default_filter != NULL;
|
||||||
original_user_abort_setting = PG(ignore_user_abort);
|
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();
|
go_frankenphp_main_thread_is_ready();
|
||||||
|
|
||||||
/* channel closed, shutdown gracefully */
|
/* channel closed, shutdown gracefully */
|
||||||
|
|||||||
@@ -160,6 +160,19 @@ func testHelloWorld(t *testing.T, opts *testOptions) {
|
|||||||
}, opts)
|
}, 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_module(t *testing.T) { testFinishRequest(t, nil) }
|
||||||
func TestFinishRequest_worker(t *testing.T) {
|
func TestFinishRequest_worker(t *testing.T) {
|
||||||
testFinishRequest(t, &testOptions{workerScript: "finish-request.php"})
|
testFinishRequest(t, &testOptions{workerScript: "finish-request.php"})
|
||||||
|
|||||||
@@ -188,12 +188,11 @@ func TestReturnAnErrorIf2WorkersHaveTheSameFileName(t *testing.T) {
|
|||||||
workersByName = map[string]*worker{}
|
workersByName = map[string]*worker{}
|
||||||
workersByPath = map[string]*worker{}
|
workersByPath = map[string]*worker{}
|
||||||
w, err1 := newWorker(workerOpt{fileName: testDataPath + "/index.php"})
|
w, err1 := newWorker(workerOpt{fileName: testDataPath + "/index.php"})
|
||||||
|
assert.NoError(t, err1)
|
||||||
workers = append(workers, w)
|
workers = append(workers, w)
|
||||||
workersByName[w.name] = w
|
workersByName[w.name] = w
|
||||||
workersByPath[w.fileName] = w
|
workersByPath[w.fileName] = w
|
||||||
_, err2 := newWorker(workerOpt{fileName: testDataPath + "/index.php"})
|
_, err2 := newWorker(workerOpt{fileName: testDataPath + "/index.php"})
|
||||||
|
|
||||||
assert.NoError(t, err1)
|
|
||||||
assert.Error(t, err2, "two workers cannot have the same filename")
|
assert.Error(t, err2, "two workers cannot have the same filename")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,12 +201,11 @@ func TestReturnAnErrorIf2ModuleWorkersHaveTheSameName(t *testing.T) {
|
|||||||
workersByName = map[string]*worker{}
|
workersByName = map[string]*worker{}
|
||||||
workersByPath = map[string]*worker{}
|
workersByPath = map[string]*worker{}
|
||||||
w, err1 := newWorker(workerOpt{fileName: testDataPath + "/index.php", name: "workername"})
|
w, err1 := newWorker(workerOpt{fileName: testDataPath + "/index.php", name: "workername"})
|
||||||
|
assert.NoError(t, err1)
|
||||||
workers = append(workers, w)
|
workers = append(workers, w)
|
||||||
workersByName[w.name] = w
|
workersByName[w.name] = w
|
||||||
workersByPath[w.fileName] = w
|
workersByPath[w.fileName] = w
|
||||||
_, err2 := newWorker(workerOpt{fileName: testDataPath + "/hello.php", name: "workername"})
|
_, err2 := newWorker(workerOpt{fileName: testDataPath + "/hello.php", name: "workername"})
|
||||||
|
|
||||||
assert.NoError(t, err1)
|
|
||||||
assert.Error(t, err2, "two workers cannot have the same name")
|
assert.Error(t, err2, "two workers cannot have the same name")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user