Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions frankenphp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */
Expand Down
13 changes: 13 additions & 0 deletions frankenphp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down
6 changes: 2 additions & 4 deletions phpmainthread_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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")
}

Expand Down
Loading