From 7ad3ac23a6409ddbe33514a227875a6c737ee6e0 Mon Sep 17 00:00:00 2001 From: Alliballibaba Date: Mon, 9 Mar 2026 13:20:48 +0100 Subject: [PATCH 1/3] Adds opcache preload test. --- frankenphp_test.go | 39 ++++++++++++++++++++++++++++++++++++++ testdata/preload-check.php | 12 ++++++++++++ testdata/preload.php | 5 +++++ 3 files changed, 56 insertions(+) create mode 100644 testdata/preload-check.php create mode 100644 testdata/preload.php diff --git a/frankenphp_test.go b/frankenphp_test.go index 0301b20276..90baa7617e 100644 --- a/frankenphp_test.go +++ b/frankenphp_test.go @@ -22,6 +22,7 @@ import ( "net/url" "os" "os/exec" + "os/user" "path/filepath" "strconv" "strings" @@ -1289,3 +1290,41 @@ func TestSessionNoLeakAfterExit_worker(t *testing.T) { realServer: true, }) } + +func TestOpcachePreload_module(t *testing.T) { + testOpcachePreload(t, nil) +} + +func TestOpcachePreload_worker(t *testing.T) { + testOpcachePreload(t, &testOptions{workerScript: "preload-check.php", nbWorkers: 1, nbParallelRequests: 1}) +} + +func testOpcachePreload(t *testing.T, opts *testOptions) { + cwd, _ := os.Getwd() + preloadScript := cwd + "/testdata/preload.php" + + u, err := user.Current() + require.NoError(t, err) + + phpIni := map[string]string{ + "opcache.enable": "1", + "opcache.preload": preloadScript, + "opcache.preload_user": u.Username, + } + + if opts == nil { + opts = &testOptions{} + } + if opts.phpIni == nil { + opts.phpIni = phpIni + } else { + for k, v := range phpIni { + opts.phpIni[k] = v + } + } + + runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) { + body, _ := testGet("http://example.com/preload-check.php", handler, t) + assert.Equal(t, "I am preloaded", body) + }, opts) +} diff --git a/testdata/preload-check.php b/testdata/preload-check.php new file mode 100644 index 0000000000..a7afbca752 --- /dev/null +++ b/testdata/preload-check.php @@ -0,0 +1,12 @@ + Date: Mon, 9 Mar 2026 13:25:49 +0100 Subject: [PATCH 2/3] cleanup --- frankenphp_test.go | 17 +++-------------- testdata/preload.php | 2 ++ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/frankenphp_test.go b/frankenphp_test.go index 90baa7617e..d806b5117a 100644 --- a/frankenphp_test.go +++ b/frankenphp_test.go @@ -1292,11 +1292,11 @@ func TestSessionNoLeakAfterExit_worker(t *testing.T) { } func TestOpcachePreload_module(t *testing.T) { - testOpcachePreload(t, nil) + testOpcachePreload(t, &testOptions{env: map[string]string{"TEST": "123"}}) } func TestOpcachePreload_worker(t *testing.T) { - testOpcachePreload(t, &testOptions{workerScript: "preload-check.php", nbWorkers: 1, nbParallelRequests: 1}) + testOpcachePreload(t, &testOptions{workerScript: "preload-check.php", nbWorkers: 1, nbParallelRequests: 1, env: map[string]string{"TEST": "123"}}) } func testOpcachePreload(t *testing.T, opts *testOptions) { @@ -1306,23 +1306,12 @@ func testOpcachePreload(t *testing.T, opts *testOptions) { u, err := user.Current() require.NoError(t, err) - phpIni := map[string]string{ + opts.phpIni = map[string]string{ "opcache.enable": "1", "opcache.preload": preloadScript, "opcache.preload_user": u.Username, } - if opts == nil { - opts = &testOptions{} - } - if opts.phpIni == nil { - opts.phpIni = phpIni - } else { - for k, v := range phpIni { - opts.phpIni[k] = v - } - } - runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) { body, _ := testGet("http://example.com/preload-check.php", handler, t) assert.Equal(t, "I am preloaded", body) diff --git a/testdata/preload.php b/testdata/preload.php index 99208156a7..09cf49258f 100644 --- a/testdata/preload.php +++ b/testdata/preload.php @@ -1,5 +1,7 @@ Date: Mon, 9 Mar 2026 13:32:26 +0100 Subject: [PATCH 3/3] Accesses ENV during startup. --- testdata/preload.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/testdata/preload.php b/testdata/preload.php index 09cf49258f..a4ac6c954f 100644 --- a/testdata/preload.php +++ b/testdata/preload.php @@ -1,7 +1,8 @@