Skip to content

Commit 9cfa7b3

Browse files
fix: opcache_preload in PHP 8.2 (#2284)
Fixes the Docker image tests currently failing in CI.
1 parent 097563d commit 9cfa7b3

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

frankenphp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ int frankenphp_execute_script(char *file_name) {
12271227

12281228
zend_destroy_file_handle(&file_handle);
12291229

1230-
/* Reset the sandboxed environment */
1230+
/* Reset the sandboxed environment if it is in use */
12311231
if (sandboxed_env != NULL) {
12321232
zend_hash_release(sandboxed_env);
12331233
sandboxed_env = NULL;

frankenphp_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ func TestMain(m *testing.M) {
141141
slog.SetDefault(slog.New(slog.DiscardHandler))
142142
}
143143

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

164164
func TestEnvVarsInPhpIni(t *testing.T) {
165-
t.Setenv("OPCACHE_ENABLE", "0")
166-
167165
runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, _ int) {
168166
body, _ := testGet("http://example.com/ini.php?key=opcache.enable", handler, t)
169167
assert.Equal(t, "opcache.enable:0", body)
170168
}, &testOptions{
171169
phpIni: map[string]string{
172-
"opcache.enable": "${OPCACHE_ENABLE}",
170+
"opcache.enable": "${LITERAL_ZERO}",
173171
},
174172
})
175173
}
@@ -1305,20 +1303,26 @@ func TestSessionNoLeakAfterExit_worker(t *testing.T) {
13051303
}
13061304

13071305
func TestOpcachePreload_module(t *testing.T) {
1308-
testOpcachePreload(t, &testOptions{env: map[string]string{"TEST": "123"}})
1306+
testOpcachePreload(t, &testOptions{env: map[string]string{"TEST": "123"}, realServer: true})
13091307
}
13101308

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

13151313
func testOpcachePreload(t *testing.T, opts *testOptions) {
1314+
if frankenphp.Version().VersionID <= 80300 {
1315+
t.Skip("This test is only supported in PHP 8.3 and above")
1316+
return
1317+
}
1318+
13161319
cwd, _ := os.Getwd()
13171320
preloadScript := cwd + "/testdata/preload.php"
13181321

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

1325+
// use opcache.log_verbosity_level:4 for debugging
13221326
opts.phpIni = map[string]string{
13231327
"opcache.enable": "1",
13241328
"opcache.preload": preloadScript,

0 commit comments

Comments
 (0)