mirror of
https://github.com/php/frankenphp.git
synced 2026-03-24 00:52:11 +01:00
chore: various cleanups
This commit is contained in:
@@ -74,10 +74,10 @@ type FrankenPHPApp struct {
|
||||
}
|
||||
|
||||
// CaddyModule returns the Caddy module information.
|
||||
func (a FrankenPHPApp) CaddyModule() caddy.ModuleInfo {
|
||||
func (f FrankenPHPApp) CaddyModule() caddy.ModuleInfo {
|
||||
return caddy.ModuleInfo{
|
||||
ID: "frankenphp",
|
||||
New: func() caddy.Module { return &a },
|
||||
New: func() caddy.Module { return &f },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||
}
|
||||
|
||||
if wc.FileName == "" {
|
||||
return errors.New(`The "file" argument must be specified`)
|
||||
return errors.New(`the "file" argument must be specified`)
|
||||
}
|
||||
|
||||
if frankenphp.EmbeddedAppPath != "" && filepath.IsLocal(wc.FileName) {
|
||||
@@ -592,7 +592,7 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
|
||||
|
||||
// route to actually pass requests to PHP files;
|
||||
// match only requests that are for PHP files
|
||||
pathList := []string{}
|
||||
var pathList []string
|
||||
for _, ext := range extensions {
|
||||
pathList = append(pathList, "*"+ext)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ Executes a PHP script similarly to the CLI SAPI.`,
|
||||
})
|
||||
}
|
||||
|
||||
func cmdPHPCLI(fs caddycmd.Flags) (int, error) {
|
||||
func cmdPHPCLI(caddycmd.Flags) (int, error) {
|
||||
args := os.Args[2:]
|
||||
if len(args) < 1 {
|
||||
return 1, errors.New("the path to the PHP script is required")
|
||||
|
||||
@@ -179,7 +179,7 @@ func cmdPHPServer(fs caddycmd.Flags) (int, error) {
|
||||
|
||||
// route to actually pass requests to PHP files;
|
||||
// match only requests that are for PHP files
|
||||
pathList := []string{}
|
||||
var pathList []string
|
||||
for _, ext := range extensions {
|
||||
pathList = append(pathList, "*"+ext)
|
||||
}
|
||||
|
||||
4
embed.go
4
embed.go
@@ -17,7 +17,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// The path of the embedded PHP application (empty if none)
|
||||
// EmbeddedAppPath contains the path of the embedded PHP application (empty if none)
|
||||
var EmbeddedAppPath string
|
||||
|
||||
//go:embed app.tar
|
||||
@@ -35,7 +35,7 @@ func init() {
|
||||
appPath := filepath.Join(os.TempDir(), "frankenphp_"+string(embeddedAppChecksum))
|
||||
|
||||
if err := untar(appPath); err != nil {
|
||||
os.RemoveAll(appPath)
|
||||
_ = os.RemoveAll(appPath)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -56,13 +56,11 @@ var contextKey = contextKeyStruct{}
|
||||
|
||||
var (
|
||||
InvalidRequestError = errors.New("not a FrankenPHP request")
|
||||
AlreaydStartedError = errors.New("FrankenPHP is already started")
|
||||
AlreadyStartedError = errors.New("FrankenPHP is already started")
|
||||
InvalidPHPVersionError = errors.New("FrankenPHP is only compatible with PHP 8.2+")
|
||||
ZendSignalsError = errors.New("Zend Signals are enabled, recompile PHP with --disable-zend-signals")
|
||||
NotEnoughThreads = errors.New("the number of threads must be superior to the number of workers")
|
||||
MainThreadCreationError = errors.New("error creating the main thread")
|
||||
RequestContextCreationError = errors.New("error during request context creation")
|
||||
RequestStartupError = errors.New("error during PHP request startup")
|
||||
ScriptExecutionError = errors.New("error during PHP script execution")
|
||||
|
||||
requestChan chan *http.Request
|
||||
@@ -280,7 +278,7 @@ func calculateMaxThreads(opt *opt) error {
|
||||
// Init starts the PHP runtime and the configured workers.
|
||||
func Init(options ...Option) error {
|
||||
if requestChan != nil {
|
||||
return AlreaydStartedError
|
||||
return AlreadyStartedError
|
||||
}
|
||||
|
||||
// Ignore all SIGPIPE signals to prevent weird issues with systemd: https://github.com/dunglas/frankenphp/issues/1020
|
||||
@@ -371,7 +369,7 @@ func Shutdown() {
|
||||
|
||||
// Remove the installed app
|
||||
if EmbeddedAppPath != "" {
|
||||
os.RemoveAll(EmbeddedAppPath)
|
||||
_ = os.RemoveAll(EmbeddedAppPath)
|
||||
}
|
||||
|
||||
logger.Debug("FrankenPHP shut down")
|
||||
|
||||
@@ -35,8 +35,8 @@ var (
|
||||
reloadWaitGroup sync.WaitGroup
|
||||
// we are passing the logger from the main package to the watcher
|
||||
logger *zap.Logger
|
||||
AlreadyStartedError = errors.New("The watcher is already running")
|
||||
UnableToStartWatching = errors.New("Unable to start the watcher")
|
||||
AlreadyStartedError = errors.New("the watcher is already running")
|
||||
UnableToStartWatching = errors.New("unable to start the watcher")
|
||||
)
|
||||
|
||||
func InitWatcher(filePatterns []string, callback func(), zapLogger *zap.Logger) error {
|
||||
|
||||
19
metrics.go
19
metrics.go
@@ -1,11 +1,12 @@
|
||||
package frankenphp
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var metricsNameRegex = regexp.MustCompile(`\W+`)
|
||||
@@ -43,19 +44,19 @@ type Metrics interface {
|
||||
|
||||
type nullMetrics struct{}
|
||||
|
||||
func (n nullMetrics) StartWorker(name string) {
|
||||
func (n nullMetrics) StartWorker(string) {
|
||||
}
|
||||
|
||||
func (n nullMetrics) ReadyWorker(name string) {
|
||||
func (n nullMetrics) ReadyWorker(string) {
|
||||
}
|
||||
|
||||
func (n nullMetrics) StopWorker(name string, reason StopReason) {
|
||||
func (n nullMetrics) StopWorker(string, StopReason) {
|
||||
}
|
||||
|
||||
func (n nullMetrics) TotalWorkers(name string, num int) {
|
||||
func (n nullMetrics) TotalWorkers(string, int) {
|
||||
}
|
||||
|
||||
func (n nullMetrics) TotalThreads(num int) {
|
||||
func (n nullMetrics) TotalThreads(int) {
|
||||
}
|
||||
|
||||
func (n nullMetrics) StartRequest() {
|
||||
@@ -64,10 +65,10 @@ func (n nullMetrics) StartRequest() {
|
||||
func (n nullMetrics) StopRequest() {
|
||||
}
|
||||
|
||||
func (n nullMetrics) StopWorkerRequest(name string, duration time.Duration) {
|
||||
func (n nullMetrics) StopWorkerRequest(string, time.Duration) {
|
||||
}
|
||||
|
||||
func (n nullMetrics) StartWorkerRequest(name string) {
|
||||
func (n nullMetrics) StartWorkerRequest(string) {
|
||||
}
|
||||
|
||||
func (n nullMetrics) Shutdown() {
|
||||
@@ -133,7 +134,7 @@ func (m *PrometheusMetrics) getIdentity(name string) (string, error) {
|
||||
return actualName, nil
|
||||
}
|
||||
|
||||
func (m *PrometheusMetrics) TotalWorkers(name string, num int) {
|
||||
func (m *PrometheusMetrics) TotalWorkers(name string, _ int) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
|
||||
@@ -46,14 +46,16 @@ func WithRequestResolvedDocumentRoot(documentRoot string) RequestOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithRequestSplitPath contains a list of split path strings.
|
||||
//
|
||||
// The path in the URL will be split into two, with the first piece ending
|
||||
// with the value of SplitPath. The first piece will be assumed as the
|
||||
// with the value of splitPath. The first piece will be assumed as the
|
||||
// actual resource (CGI script) name, and the second piece will be set to
|
||||
// PATH_INFO for the CGI script to use.
|
||||
//
|
||||
// Future enhancements should be careful to avoid CVE-2019-11043,
|
||||
// which can be mitigated with use of a try_files-like behavior
|
||||
// that 404s if the fastcgi path info is not found.
|
||||
// that 404s if the FastCGI path info is not found.
|
||||
func WithRequestSplitPath(splitPath []string) RequestOption {
|
||||
return func(o *FrankenPHPContext) error {
|
||||
o.splitPath = splitPath
|
||||
|
||||
@@ -34,7 +34,7 @@ var (
|
||||
workersAreReady atomic.Bool
|
||||
workersAreDone atomic.Bool
|
||||
workersDone chan interface{}
|
||||
workers map[string]*worker = make(map[string]*worker)
|
||||
workers = make(map[string]*worker)
|
||||
)
|
||||
|
||||
func initWorkers(opt []workerOpt) error {
|
||||
@@ -203,7 +203,7 @@ func drainWorkers() {
|
||||
}
|
||||
|
||||
func restartWorkersOnFileChanges(workerOpts []workerOpt) error {
|
||||
directoriesToWatch := []string{}
|
||||
var directoriesToWatch []string
|
||||
for _, w := range workerOpts {
|
||||
directoriesToWatch = append(directoriesToWatch, w.watch...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user