Skip to content

Commit bb3f730

Browse files
committed
feat: allow to customize EmbeddedAppPath
1 parent 151ea1c commit bb3f730

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

embed.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ import (
1717
"time"
1818
)
1919

20-
// EmbeddedAppPath contains the path of the embedded PHP application (empty if none)
20+
// EmbeddedAppPath contains the path of the embedded PHP application (empty if none).
21+
// It can be set at build time using -ldflags to override the default extraction path:
22+
//
23+
// go build -ldflags "-X github.com/dunglas/frankenphp.EmbeddedAppPath=/app" ...
24+
//
25+
// When set, the embedded app is extracted to this fixed path instead of a temp
26+
// directory with a checksum suffix. This is useful when the app contains
27+
// pre-compiled artifacts (e.g. OPcache file cache) that reference absolute paths
28+
// and need a predictable extraction location.
2129
var EmbeddedAppPath string
2230

2331
//go:embed app.tar
@@ -32,14 +40,14 @@ func init() {
3240
return
3341
}
3442

35-
appPath := filepath.Join(os.TempDir(), "frankenphp_"+string(embeddedAppChecksum))
43+
if EmbeddedAppPath == "" {
44+
EmbeddedAppPath = filepath.Join(os.TempDir(), "frankenphp_"+string(embeddedAppChecksum))
45+
}
3646

37-
if err := untar(appPath); err != nil {
38-
_ = os.RemoveAll(appPath)
47+
if err := untar(EmbeddedAppPath); err != nil {
48+
_ = os.RemoveAll(EmbeddedAppPath)
3949
panic(err)
4050
}
41-
42-
EmbeddedAppPath = appPath
4351
}
4452

4553
// untar reads the tar file from r and writes it into dir.

0 commit comments

Comments
 (0)