From 64f2d1e9c73461255800abce00097fabfbdd4f01 Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Thu, 20 Jun 2024 06:37:54 +0300 Subject: [PATCH] feat: add support for tcp sockets for php-fpm --- performer/cli.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/performer/cli.go b/performer/cli.go index 67e4e40..a4b6ab8 100644 --- a/performer/cli.go +++ b/performer/cli.go @@ -3,8 +3,6 @@ package performer import ( "encoding/json" "fmt" - "github.com/Automattic/cron-control-runner/logger" - "github.com/Automattic/cron-control-runner/metrics" "io" "math/rand" "net/http" @@ -13,6 +11,9 @@ import ( "strings" "time" + "github.com/Automattic/cron-control-runner/logger" + "github.com/Automattic/cron-control-runner/metrics" + "github.com/yookoala/gofast" ) @@ -58,12 +59,17 @@ func NewCLI(wpCLIPath string, wpPath string, fpmURL string, metrics metrics.Mana if fpmURL != "" { var err error parsedURL, err := url.Parse(fpmURL) - if err != nil || parsedURL == nil || parsedURL.Scheme != "unix" || parsedURL.Path == "" { + if err != nil || parsedURL == nil || (parsedURL.Scheme == "unix" && parsedURL.Path == "") || ((parsedURL.Scheme == "tcp" || parsedURL.Scheme == "tcp4" || parsedURL.Scheme == "tcp6") && parsedURL.Host == "") { logger.Errorf("problem parsing FPM url %q: %v", fpmURL, err) panic(err) } logger.Infof("Using FPM runtime at %q", parsedURL) - performer.fpm = gofast.SimpleClientFactory(gofast.SimpleConnFactory(parsedURL.Scheme, parsedURL.Path)) + proto := parsedURL.Scheme + address := parsedURL.Host + if proto == "unix" { + address = parsedURL.Path + } + performer.fpm = gofast.SimpleClientFactory(gofast.SimpleConnFactory(proto, address)) } return performer