44package caddy
55
66import (
7+ "crypto/sha256"
8+ "encoding/hex"
79 "encoding/json"
810 "errors"
911 "fmt"
@@ -12,7 +14,6 @@ import (
1214 "strconv"
1315 "strings"
1416 "time"
15- "unsafe"
1617
1718 "github.com/dunglas/frankenphp/internal/fastabs"
1819
@@ -60,7 +61,7 @@ type workerConfig struct {
6061 // Directories to watch for file changes
6162 Watch []string `json:"watch,omitempty"`
6263 // ModuleID identifies which module created this worker
63- ModuleID uintptr `json:"module_id,omitempty"`
64+ ModuleID string `json:"module_id,omitempty"`
6465}
6566
6667type FrankenPHPApp struct {
@@ -356,6 +357,8 @@ type FrankenPHPModule struct {
356357 ResolveRootSymlink * bool `json:"resolve_root_symlink,omitempty"`
357358 // Env sets an extra environment variable to the given value. Can be specified more than once for multiple environment variables.
358359 Env map [string ]string `json:"env,omitempty"`
360+ // ModuleID is the module ID that created this request.
361+ ModuleID string `json:"-"`
359362 // Workers configures the worker scripts to start.
360363 Workers []workerConfig `json:"workers,omitempty"`
361364
@@ -429,9 +432,13 @@ func (f *FrankenPHPModule) Provision(ctx caddy.Context) error {
429432 }
430433 }
431434
435+ data := []byte (f .Root + strings .Join (f .SplitPath , "," ) + time .Now ().String ())
436+ hash := sha256 .Sum256 (data )
437+ f .ModuleID = hex .EncodeToString (hash [:8 ])
438+
432439 if len (f .Workers ) > 0 {
433- for i := range f .Workers {
434- f . Workers [ i ]. ModuleID = uintptr ( unsafe . Pointer ( f ))
440+ for _ , w := range f .Workers {
441+ w . ModuleID = f . ModuleID
435442 }
436443 moduleWorkers = append (moduleWorkers , f .Workers ... )
437444 }
@@ -471,7 +478,7 @@ func (f *FrankenPHPModule) ServeHTTP(w http.ResponseWriter, r *http.Request, _ c
471478 frankenphp .WithRequestSplitPath (f .SplitPath ),
472479 frankenphp .WithRequestPreparedEnv (env ),
473480 frankenphp .WithOriginalRequest (& origReq ),
474- frankenphp .WithModuleID (uintptr ( unsafe . Pointer ( f )) ),
481+ frankenphp .WithModuleID (f . ModuleID ),
475482 )
476483
477484 if err != nil {
0 commit comments