diff --git a/frankenphp_test.go b/frankenphp_test.go index 3b8c274d..f8279d80 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" @@ -1302,3 +1303,30 @@ func TestSessionNoLeakAfterExit_worker(t *testing.T) { realServer: true, }) } + +func TestOpcachePreload_module(t *testing.T) { + 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, env: map[string]string{"TEST": "123"}}) +} + +func testOpcachePreload(t *testing.T, opts *testOptions) { + cwd, _ := os.Getwd() + preloadScript := cwd + "/testdata/preload.php" + + u, err := user.Current() + require.NoError(t, err) + + opts.phpIni = map[string]string{ + "opcache.enable": "1", + "opcache.preload": preloadScript, + "opcache.preload_user": u.Username, + } + + 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 00000000..a7afbca7 --- /dev/null +++ b/testdata/preload-check.php @@ -0,0 +1,12 @@ +