Support listening on existing file descriptors (FDs) with SocketServer
#269
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changeset adds support for listening on existing file descriptors (FDs) with the
SocketServer
:This is particularly useful when using systemd socket activation like this:
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
andUnixServer
except for the constructor usingfopen('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