Skip to content

Commit 2380fd3

Browse files
committed
chore(integration_runner): Refactors code to handle opcache settigns
1 parent f25f685 commit 2380fd3

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

daemon/internal/newrelic/integration/transaction.go

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,61 @@ func flatten(x map[string]string) []string {
4141
return s
4242
}
4343

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+
4491
// PhpTx constructs non-Web transactions to be executed by PHP.
4592
func PhpTx(src Script, env, settings map[string]string, ctx *Context) (Tx, error) {
4693
// Note: file path must be relative to the working directory.
4794
var txn Tx
4895

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)
5099

51100
if ctx.Valgrind != "" && settings["newrelic.appname"] != "skipif" {
52101
txn = &ValgrindCLI{
@@ -83,6 +132,8 @@ func CgiTx(src Script, env, settings map[string]string, headers http.Header, ctx
83132
var err error
84133
var txn Tx
85134

135+
newSettings := fixupSettings(ctx.CGI, env, settings, ctx)
136+
86137
req := &http.Request{
87138
Method: env["REQUEST_METHOD"],
88139
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
113164
handler: &cgi.Handler{
114165
Path: ctx.CGI,
115166
Dir: src.Dir(),
116-
Args: phpArgs(nil, "", false, settings),
167+
Args: phpArgs(nil, "", false, newSettings),
117168
},
118169
},
119170
Valgrind: ctx.Valgrind,
@@ -144,7 +195,7 @@ func CgiTx(src Script, env, settings map[string]string, headers http.Header, ctx
144195
handler: &cgi.Handler{
145196
Path: ctx.CGI,
146197
Dir: src.Dir(),
147-
Args: phpArgs(nil, "", false, settings),
198+
Args: phpArgs(nil, "", false, newSettings),
148199
},
149200
}
150201
tx.handler.Env = append(tx.handler.Env,

0 commit comments

Comments
 (0)