2022-10-04 12:36:03 +00:00
|
|
|
package frankenphp
|
|
|
|
|
2022-10-04 15:42:45 +00:00
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
2022-10-04 12:36:03 +00:00
|
|
|
|
|
|
|
// Option instances allow to configure the SAP.
|
|
|
|
type Option func(h *opt) error
|
|
|
|
|
|
|
|
// opt contains the available options.
|
|
|
|
//
|
|
|
|
// If you change this, also update the Caddy module and the documentation.
|
|
|
|
type opt struct {
|
|
|
|
numThreads int
|
|
|
|
workers []workerOpt
|
2022-10-04 15:42:45 +00:00
|
|
|
logger *zap.Logger
|
2022-10-04 12:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type workerOpt struct {
|
|
|
|
fileName string
|
|
|
|
num int
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithNumThreads allows to configure the number of PHP threads to start (worker threads excluded).
|
|
|
|
func WithNumThreads(numThreads int) Option {
|
|
|
|
return func(o *opt) error {
|
|
|
|
o.numThreads += -runtime.NumCPU() + numThreads
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithWorkers allow to start worker goroutines.
|
|
|
|
func WithWorkers(fileName string, num int) Option {
|
|
|
|
return func(o *opt) error {
|
|
|
|
o.workers = append(o.workers, workerOpt{fileName, num})
|
|
|
|
o.numThreads += num
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2022-10-04 15:42:45 +00:00
|
|
|
|
|
|
|
// WithLogger sets the global logger to use
|
|
|
|
func WithLogger(l *zap.Logger) Option {
|
|
|
|
return func(o *opt) error {
|
|
|
|
o.logger = l
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|