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
2 changes: 1 addition & 1 deletion frankenphp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ int frankenphp_execute_script(char *file_name) {

zend_destroy_file_handle(&file_handle);

/* Reset the sandboxed environment */
/* Reset the sandboxed environment if it is in use */
if (sandboxed_env != NULL) {
zend_hash_release(sandboxed_env);
sandboxed_env = NULL;
Expand Down
18 changes: 11 additions & 7 deletions frankenphp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func TestMain(m *testing.M) {
slog.SetDefault(slog.New(slog.DiscardHandler))
}

// setup custom environment var for TestWorkerHasOSEnvironmentVariableInSERVER
if os.Setenv("CUSTOM_OS_ENV_VARIABLE", "custom_env_variable_value") != nil {
// setup custom environment var for TestWorkerHasOSEnvironmentVariableInSERVER and TestPhpIni
if os.Setenv("CUSTOM_OS_ENV_VARIABLE", "custom_env_variable_value") != nil || os.Setenv("LITERAL_ZERO", "0") != nil {
fmt.Println("Failed to set environment variable for tests")
os.Exit(1)
}
Expand All @@ -162,14 +162,12 @@ func testHelloWorld(t *testing.T, opts *testOptions) {
}

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}",
"opcache.enable": "${LITERAL_ZERO}",
},
})
}
Expand Down Expand Up @@ -1305,20 +1303,26 @@ func TestSessionNoLeakAfterExit_worker(t *testing.T) {
}

func TestOpcachePreload_module(t *testing.T) {
testOpcachePreload(t, &testOptions{env: map[string]string{"TEST": "123"}})
testOpcachePreload(t, &testOptions{env: map[string]string{"TEST": "123"}, realServer: true})
}

func TestOpcachePreload_worker(t *testing.T) {
testOpcachePreload(t, &testOptions{workerScript: "preload-check.php", nbWorkers: 1, nbParallelRequests: 1, env: map[string]string{"TEST": "123"}})
testOpcachePreload(t, &testOptions{workerScript: "preload-check.php", env: map[string]string{"TEST": "123"}, realServer: true})
}

func testOpcachePreload(t *testing.T, opts *testOptions) {
if frankenphp.Version().VersionID <= 80300 {
t.Skip("This test is only supported in PHP 8.3 and above")
return
}

cwd, _ := os.Getwd()
preloadScript := cwd + "/testdata/preload.php"

u, err := user.Current()
require.NoError(t, err)

// use opcache.log_verbosity_level:4 for debugging
opts.phpIni = map[string]string{
"opcache.enable": "1",
"opcache.preload": preloadScript,
Expand Down
Loading