Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fpm sapi listen always on sockets #218

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 19 additions & 4 deletions local/php/php_server.go
Expand Up @@ -32,6 +32,7 @@ import (
"net/url"
"os"
"os/exec"
"path"
"runtime"
"strconv"
"strings"
Expand All @@ -46,6 +47,7 @@ import (
"github.com/symfony-cli/symfony-cli/local/html"
"github.com/symfony-cli/symfony-cli/local/pid"
"github.com/symfony-cli/symfony-cli/local/process"
"github.com/symfony-cli/symfony-cli/util"
)

// Server represents a PHP server process (can be php-fpm, php-cgi, or php-cli)
Expand Down Expand Up @@ -98,11 +100,18 @@ func (p *Server) Start(ctx context.Context, pidFile *pid.PidFile) (*pid.PidFile,
var binName, workerName string
var args []string
if p.Version.IsFPMServer() {
socketDir := path.Join(util.GetHomeDir(), name(p.projectDir))

if _, err := os.Stat(socketDir); os.IsNotExist(err) {
os.MkdirAll(socketDir, os.ModePerm)
}

p.addr = path.Join(util.GetHomeDir(), name(p.projectDir), "php-fpm.sock")
shyim marked this conversation as resolved.
Show resolved Hide resolved
fpmConfigFile := p.fpmConfigFile()
if err := ioutil.WriteFile(fpmConfigFile, []byte(p.defaultFPMConf()), 0644); err != nil {
return nil, nil, errors.WithStack(err)
}
pathsToRemove = append(pathsToRemove, fpmConfigFile)
pathsToRemove = append(pathsToRemove, fpmConfigFile, p.addr)
binName = "php-fpm"
workerName = "PHP-FPM"
args = []string{p.Version.ServerPath(), "--nodaemonize", "--fpm-config", fpmConfigFile}
Expand Down Expand Up @@ -150,7 +159,7 @@ func (p *Server) Start(ctx context.Context, pidFile *pid.PidFile) (*pid.PidFile,
Args: args,
scriptDir: p.projectDir,
}
p.logger.Info().Int("port", port).Msg("listening")
p.logger.Info().Str("listen", p.addr).Msg("listening")

phpPidFile := pid.New(pidFile.Dir, append([]string{p.Version.ServerPath()}, e.Args[1:]...))
if phpPidFile.IsRunning() {
Expand Down Expand Up @@ -224,8 +233,14 @@ func (p *Server) serveFastCGI(env map[string]string, w http.ResponseWriter, r *h
max := 10
i := 0
for {
if fcgi, err = fcgiclient.Dial("tcp", p.addr); err == nil {
break
if p.Version.IsFPMServer() {
if fcgi, err = fcgiclient.Dial("unix", p.addr); err == nil {
break
}
} else {
if fcgi, err = fcgiclient.Dial("tcp", p.addr); err == nil {
break
}
Comment on lines +228 to +235
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should not refactor this to have a simpler dialer internal function here.
wdyt @fabpot ?

}
i++
if i > max {
Expand Down