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

Systemd Socket Activation - File Descriptor with HTTP Server #164

Closed
doc987 opened this issue May 27, 2018 · 2 comments · Fixed by #269
Closed

Systemd Socket Activation - File Descriptor with HTTP Server #164

doc987 opened this issue May 27, 2018 · 2 comments · Fixed by #269

Comments

@doc987
Copy link

doc987 commented May 27, 2018

How do I start \React\Socket\Server using systemd socket activation? There would need to be a way to accept a file descriptor from systemd, and then use that file descriptor to instantiate \React\Socket\Server.

@clue
Copy link
Member

clue commented May 27, 2018

Thank you for bringing this up! Right now, this component does not support listening on existing file descriptors and I think this would be a very useful addition to this package!

PHP does technically support this via the php://fd/n wrapper since PHP 5.3.6 (http://php.net/manual/de/wrappers.php.php#refsect1-wrappers.php-changelog). I recall this was briefly discussed in reactphp/reactphp#252 a while ago, but this never quite made it.

I've just looked into this again and the existing component is pretty much already compatible with this except that this needs to use fopen() instead of stream_socket_server(). Here's a gist of how this can be used in PHP (which suggests that this is apparently broken in PHP 7.1.2 to PHP 7.1.6 and not supported on HHVM at all): https://3v4l.org/PWjMH

Implementing this as part of this package means that we would have to come up with some tests to verify correct execution. PHP does not currently expose a sane way to access the underlying file descriptor for an existing socket or stream resource (https://stackoverflow.com/questions/5600811/fopen-and-getting-system-file-descriptor, reactphp/child-process#51 and maybe https://github.com/YuriyNasretdinov/phprocksyd/blob/master/php-fd.patch). On Linux, we may use /proc/self/fd/ to iterate over all existing file descriptors and on Mac we may be able to use lsof (https://unix.stackexchange.com/questions/235979/how-do-i-find-out-more-about-socket-files-in-proc-fd).

Long story short, here's a gist with a WIP version of a FdServer to show how this could potentially be used with ReactPHP: https://gist.github.com/clue/fa4f1ddf26f2f8727232215a0f700e09

Maybe somebody else feels like giving this a try or looking into this? Any feedback is appreciated 👍

@phpbg
Copy link

phpbg commented Jan 24, 2019

This would be really nice to improve security when listening privileged ports

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

Successfully merging a pull request may close this issue.

3 participants