@@ -41,12 +41,61 @@ func flatten(x map[string]string) []string {
41
41
return s
42
42
}
43
43
44
+ // fixup settings to handle opcache module loading gracefully
45
+ //
46
+ // php_executable is the name to the PHP executable
47
+ // env is the environment variables to pass to the PHP process
48
+ // settings is the PHP settings to apply to the process
49
+ // ctx is the context containing configuration options
50
+ func fixupSettings (php_executable string , env , settings map [string ]string , ctx * Context ) map [string ]string {
51
+
52
+ // Make a copy of settings to avoid mutating the original map
53
+ // Need to adjust settings to opcache
54
+ phpSettings := make (map [string ]string , len (settings ))
55
+ setOPCacheEnable := true
56
+ setOPCacheEnableCLI := true
57
+
58
+ for k , v := range settings {
59
+ phpSettings [k ] = v
60
+
61
+ // see if settings affect opcache config
62
+ // if so then we will not set config below
63
+ if k == "opcache.enable" {
64
+ setOPCacheEnable = false
65
+ } else if k == "opcache.enable_cli" {
66
+ setOPCacheEnableCLI = false
67
+ }
68
+ }
69
+ if ctx .UseOPCache {
70
+ if ! ctx .OPCacheModuleLoaded [php_executable ] {
71
+ phpSettings ["zend_extension" ] = "opcache.so"
72
+ }
73
+ if setOPCacheEnable {
74
+ phpSettings ["opcache.enable" ] = "1"
75
+ }
76
+ if setOPCacheEnableCLI {
77
+ phpSettings ["opcache.enable_cli" ] = "1"
78
+ }
79
+ } else {
80
+ if setOPCacheEnable {
81
+ phpSettings ["opcache.enable" ] = "0"
82
+ }
83
+ if setOPCacheEnableCLI {
84
+ phpSettings ["opcache.enable_cli" ] = "0"
85
+ }
86
+ }
87
+
88
+ return phpSettings
89
+ }
90
+
44
91
// PhpTx constructs non-Web transactions to be executed by PHP.
45
92
func PhpTx (src Script , env , settings map [string ]string , ctx * Context ) (Tx , error ) {
46
93
// Note: file path must be relative to the working directory.
47
94
var txn Tx
48
95
49
- args := phpArgs (nil , filepath .Base (src .Name ()), false , settings )
96
+ newSettings := fixupSettings (ctx .PHP , env , settings , ctx )
97
+
98
+ args := phpArgs (nil , filepath .Base (src .Name ()), false , newSettings )
50
99
51
100
if ctx .Valgrind != "" && settings ["newrelic.appname" ] != "skipif" {
52
101
txn = & ValgrindCLI {
@@ -83,6 +132,8 @@ func CgiTx(src Script, env, settings map[string]string, headers http.Header, ctx
83
132
var err error
84
133
var txn Tx
85
134
135
+ newSettings := fixupSettings (ctx .CGI , env , settings , ctx )
136
+
86
137
req := & http.Request {
87
138
Method : env ["REQUEST_METHOD" ],
88
139
RequestURI : "/" + filepath .Base (src .Name ()) + "?" + env ["QUERY_STRING" ],
@@ -113,7 +164,7 @@ func CgiTx(src Script, env, settings map[string]string, headers http.Header, ctx
113
164
handler : & cgi.Handler {
114
165
Path : ctx .CGI ,
115
166
Dir : src .Dir (),
116
- Args : phpArgs (nil , "" , false , settings ),
167
+ Args : phpArgs (nil , "" , false , newSettings ),
117
168
},
118
169
},
119
170
Valgrind : ctx .Valgrind ,
@@ -144,7 +195,7 @@ func CgiTx(src Script, env, settings map[string]string, headers http.Header, ctx
144
195
handler : & cgi.Handler {
145
196
Path : ctx .CGI ,
146
197
Dir : src .Dir (),
147
- Args : phpArgs (nil , "" , false , settings ),
198
+ Args : phpArgs (nil , "" , false , newSettings ),
148
199
},
149
200
}
150
201
tx .handler .Env = append (tx .handler .Env ,
0 commit comments