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

Function Init

frankenphp.go:240–359  ·  view source on GitHub ↗

Init starts the PHP runtime and the configured workers.

(options ...Option)

Source from the content-addressed store, hash-verified

238
239// Init starts the PHP runtime and the configured workers.
240func Init(options ...Option) error {
241 if isRunning {
242 return ErrAlreadyStarted
243 }
244 isRunning = true
245
246 // Ignore all SIGPIPE signals to prevent weird issues with systemd: https://github.com/php/frankenphp/issues/1020
247 // Docker/Moby has a similar hack: https://github.com/moby/moby/blob/d828b032a87606ae34267e349bf7f7ccb1f6495a/cmd/dockerd/docker.go#L87-L90
248 signal.Ignore(syscall.SIGPIPE)
249
250 registerExtensions()
251
252 opt := &opt{}
253 for _, o := range options {
254 if err := o(opt); err != nil {
255 Shutdown()
256 return err
257 }
258 }
259
260 globalMu.Lock()
261
262 if opt.ctx != nil {
263 globalCtx = opt.ctx
264 opt.ctx = nil
265 }
266
267 if opt.logger != nil {
268 globalLogger = opt.logger
269 opt.logger = nil
270 }
271
272 globalMu.Unlock()
273
274 if opt.metrics != nil {
275 metrics = opt.metrics
276 }
277
278 maxWaitTime = opt.maxWaitTime
279 maxRequestsPerThread = opt.maxRequests
280
281 if opt.maxIdleTime > 0 {
282 maxIdleTime = opt.maxIdleTime
283 }
284
285 workerThreadCount, err := calculateMaxThreads(opt)
286 if err != nil {
287 Shutdown()
288 return err
289 }
290
291 metrics.TotalThreads(opt.numThreads)
292
293 config := Config()
294
295 if config.Version.MajorVersion < 8 || (config.Version.MajorVersion == 8 && config.Version.MinorVersion < 2) {
296 Shutdown()
297 return ErrInvalidPHPVersion

Callers 15

runTestFunction · 0.92
TestFailingWorkerFunction · 0.92
ExampleServeHTTPFunction · 0.92
BenchmarkHelloWorldFunction · 0.92
BenchmarkEchoFunction · 0.92
BenchmarkUncommonHeadersFunction · 0.92
ExampleServeHTTP_workersFunction · 0.92
testRegisterExtensionFunction · 0.92
mainFunction · 0.92
StartMethod · 0.92

Calls 13

registerExtensionsFunction · 0.85
ShutdownFunction · 0.85
calculateMaxThreadsFunction · 0.85
ConfigFunction · 0.85
initPHPThreadsFunction · 0.85
convertToRegularThreadFunction · 0.85
getInactivePHPThreadFunction · 0.85
initWorkersFunction · 0.85
initAutoScalingFunction · 0.85
VersionFunction · 0.85
initWatchersFunction · 0.70
TotalThreadsMethod · 0.65

Tested by 15

runTestFunction · 0.74
TestFailingWorkerFunction · 0.74
ExampleServeHTTPFunction · 0.74
BenchmarkHelloWorldFunction · 0.74
BenchmarkEchoFunction · 0.74
BenchmarkUncommonHeadersFunction · 0.74
ExampleServeHTTP_workersFunction · 0.74