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

Support listening on existing file descriptors (FDs) with SocketServer #269

Merged
merged 4 commits into from
Aug 29, 2021

Conversation

clue
Copy link
Member

@clue clue commented Aug 24, 2021

This changeset adds support for listening on existing file descriptors (FDs) with the SocketServer:

$socket = new React\Socket\SocketSever('php://fd/3');

This is particularly useful when using systemd socket activation like this:

$ systemd-socket-activate -l 8000 php examples/03-http-server.php php://fd/3

See also https://www.freedesktop.org/software/systemd/man/systemd.socket.html and http://0pointer.de/blog/projects/socket-activation.html for details on systemd socket activation.

The implementation and test suite is pretty straight forward and somewhat similar to the existing TcpServer and UnixServer except for the constructor using fopen('php://fd/3', 'r') to duplicate an existing file descriptor instead of creating a new socket server. Most of the work went into error reporting across different platforms and properly validating the given file descriptor with the limited low-level functions provided by PHP (which applies some private logic from https://github.com/clue/fd with permission). The test suite has 100% code coverage and should work on all platforms that support file descriptors and access to /dev/fd (which includes Linux and Mac and excludes Windows).

Builds on top of error reporting introduced via #266 and #267
Resolves / closes #164

@clue clue added this to the v1.10.0 milestone Aug 24, 2021
@clue clue requested a review from WyriHaximus August 24, 2021 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Systemd Socket Activation - File Descriptor with HTTP Server
2 participants