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鈥檒l 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

Conversation

shyim
Copy link
Contributor

@shyim shyim commented Nov 13, 2022

Fixes #213

Cloud based dev environments show all local listing ports and wants to forward them. But for PHP-FPM it's useless 馃槄

PHP-FPM is only available on Unix, so I didn't build a flag or so.

Before

image

After

image

Copy link
Contributor

@tucksaun tucksaun left a comment

Choose a reason for hiding this comment

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

I like the idea.

Though it probably needs more hardening in some edge cases.
For example, if FPM is still running in the background because of some bugs, the current code is able to run by just picking a new port.

local/php/php_server.go Outdated Show resolved Hide resolved
Comment on lines +236 to +243
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
}
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 ?

@shyim
Copy link
Contributor Author

shyim commented Nov 22, 2022

@tucksaun do you have an idea how to make the socket bulletproof that it gets stopped 馃. I didn't encountered a problem yet it stopped smoothly 馃

@tucksaun
Copy link
Contributor

if it always stops smoothly it means we did our job well with @fabpot :D

More seriously, if you want to simulate this situation: kill -9 the Symfony CLI binary process and remove the PID file associated with FPM (not the one in $HOME/.symfony5/var but in the subdirectory instead).
You will end up with an FPM process that the CLI is not aware of.

Currently, this means there's a 'ghost' process, but at least restarting the web server will spawn a new FPM process and it will work for the end user.
With a fixed listen address, the user gets this kind of error:

$ /Users/tucksaun/Work/src/github.com/symfony-cli/symfony-cli/symfony-cli serve
Following Web Server log file (/Users/tucksaun/.symfony5/log/2b298b2015661d81fcd2d5dcb5ddbe7e15d7b653.log)
Following PHP-FPM log file (/Users/tucksaun/.symfony5/log/2b298b2015661d81fcd2d5dcb5ddbe7e15d7b653/53fb8ec204547646acb3461995e4da5a54cc7575.log)
{"level":"error","time":"2022-11-24T17:26:15-05:00","message":"Unable to start PHP-FPM"}

 [ERROR] PHP-FPM failed to start:
 unable to bind listening socket for address '127.0.0.1:54292': Address already in use (48)
 FPM initialization failed



  PHP server exited unexpectedly: command "PHP-FPM" failed early: exit status 78

@shyim
Copy link
Contributor Author

shyim commented Nov 28, 2022

image

and the entire tree is gone for me 馃
image

@tucksaun
Copy link
Contributor

it depends on the parent behavior and how process reaping is done and if children are killed or not.

@shyim
Copy link
Contributor Author

shyim commented Nov 29, 2022

So my idea would be:

  • We enable pid in php-fpm
  • Before php-fpm starting, look for that pid file and get the pid and kill it and cleanup that file

What do you think? I guess it should solve it

@tucksaun
Copy link
Contributor

tucksaun commented Dec 6, 2022

I have the feeling that would complexify the server management code as it would introduce a special case for FPM.

The philosophy so far has been to clean up a maximum so that the CLI does not leak things but if on a rare occasion it does this is not a big deal as it is not written for production workloads.
So with that in mind, I would probably add a random seed as a suffix to the FPM socket path to be sure the process can always start.
As such, in case of failure, the best case is if the PID file and FPM are still there, the current code will kill the server before going on, but if the PID file or the FPM is not there the CLI will still be able to start.

wdyt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Start PHP-FPM as socket
2 participants