MCPcopy Index your code
hub / github.com/php/frankenphp / WithRequestDocumentRoot

Function WithRequestDocumentRoot

requestoptions.go:33–60  ·  view source on GitHub ↗

WithRequestDocumentRoot sets the root directory of the PHP application. if resolveSymlink is true, oath declared as root directory will be resolved to its absolute value after the evaluation of any symbolic links. Due to the nature of PHP opcache, root directory path is cached: when using a symlinke

(documentRoot string, resolveSymlink bool)

Source from the content-addressed store, hash-verified

31// symlink is changed without PHP being restarted; enabling this
32// directive will set $_SERVER['DOCUMENT_ROOT'] to the real directory path.
33func WithRequestDocumentRoot(documentRoot string, resolveSymlink bool) RequestOption {
34 return func(o *frankenPHPContext) (err error) {
35 v, ok := documentRootCache.Load(documentRoot)
36 if !ok {
37 // make sure file root is absolute
38 v, err = fastabs.FastAbs(documentRoot)
39 if err != nil {
40 return err
41 }
42
43 // prevent the cache to grow forever, this is a totally arbitrary value
44 if documentRootCacheLen.Load() < 1024 {
45 documentRootCache.LoadOrStore(documentRoot, v)
46 documentRootCacheLen.Add(1)
47 }
48 }
49
50 if resolveSymlink {
51 if v, err = filepath.EvalSymlinks(v.(string)); err != nil {
52 return err
53 }
54 }
55
56 o.documentRoot = v.(string)
57
58 return nil
59 }
60}
61
62// WithRequestResolvedDocumentRoot is similar to WithRequestDocumentRoot
63// but doesn't do any checks or resolving on the path to improve performance.

Callers 14

runTestFunction · 0.92
testPathInfoFunction · 0.92
ExampleServeHTTPFunction · 0.92
BenchmarkHelloWorldFunction · 0.92
BenchmarkEchoFunction · 0.92
BenchmarkUncommonHeadersFunction · 0.92
ExampleServeHTTP_workersFunction · 0.92
testRegisterExtensionFunction · 0.92
ServeHTTPMethod · 0.92
assertRequestBodyFunction · 0.85

Calls 1

FastAbsFunction · 0.92

Tested by 11

runTestFunction · 0.74
testPathInfoFunction · 0.74
ExampleServeHTTPFunction · 0.74
BenchmarkHelloWorldFunction · 0.74
BenchmarkEchoFunction · 0.74
BenchmarkUncommonHeadersFunction · 0.74
ExampleServeHTTP_workersFunction · 0.74
assertRequestBodyFunction · 0.68