From cfcbe70924a2897418904410f2563d014ddd3ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 17 Feb 2026 14:42:30 +0100 Subject: [PATCH] feat: allow to customize EmbeddedAppPath --- embed.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/embed.go b/embed.go index b99ae6a7b9..33c0118148 100644 --- a/embed.go +++ b/embed.go @@ -17,7 +17,15 @@ import ( "time" ) -// EmbeddedAppPath contains the path of the embedded PHP application (empty if none) +// EmbeddedAppPath contains the path of the embedded PHP application (empty if none). +// It can be set at build time using -ldflags to override the default extraction path: +// +// go build -ldflags "-X github.com/dunglas/frankenphp.EmbeddedAppPath=/app" ... +// +// When set, the embedded app is extracted to this fixed path instead of a temp +// directory with a checksum suffix. This is useful when the app contains +// pre-compiled artifacts (e.g. OPcache file cache) that reference absolute paths +// and need a predictable extraction location. var EmbeddedAppPath string //go:embed app.tar @@ -32,14 +40,14 @@ func init() { return } - appPath := filepath.Join(os.TempDir(), "frankenphp_"+string(embeddedAppChecksum)) + if EmbeddedAppPath == "" { + EmbeddedAppPath = filepath.Join(os.TempDir(), "frankenphp_"+string(embeddedAppChecksum)) + } - if err := untar(appPath); err != nil { - _ = os.RemoveAll(appPath) + if err := untar(EmbeddedAppPath); err != nil { + _ = os.RemoveAll(EmbeddedAppPath) panic(err) } - - EmbeddedAppPath = appPath } // untar reads the tar file from r and writes it into dir.