diff --git a/frankenphp.c b/frankenphp.c index 07f9fdf67..c25a3505f 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -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; diff --git a/frankenphp_test.go b/frankenphp_test.go index f8279d80a..df17219f3 100644 --- a/frankenphp_test.go +++ b/frankenphp_test.go @@ -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) } @@ -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}", }, }) } @@ -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,