Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions local/php/fpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import (
"os"
"os/exec"
"os/user"
"path"
"path/filepath"
"strings"

"github.com/hashicorp/go-version"
"github.com/symfony-cli/symfony-cli/util"
"github.com/symfony-cli/terminal"
)

Expand Down Expand Up @@ -117,3 +119,13 @@ func (p *Server) fpmConfigFile() string {
}
return path
}

func (p *Server) fpmSocketFile() string {
socketDir := path.Join(util.GetHomeDir(), name(p.projectDir))

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

return path.Join(util.GetHomeDir(), name(p.projectDir), "php-fpm.sock")
}
15 changes: 11 additions & 4 deletions local/php/php_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ func (p *Server) Start(ctx context.Context, pidFile *pid.PidFile) (*pid.PidFile,
var binName, workerName string
var args []string
if p.Version.IsFPMServer() {
p.addr = p.fpmSocketFile()
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 +151,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 +225,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
Member

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