-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
Allow getRemoteAddress to return the PID of a connecting Unix connection #150
Comments
Absolutely! I like the idea of returning the PID and can see some very valid use cases (local authentication etc.). If we can integrate this into this library without introducing a BC break and/or a hard dependency on |
I'd like to ask a few questions before I try to create PR for this :)
What are your thoughts on this? |
Very good points! Interestingly A single accessor may work for now, but I can clearly see some value in the remaining values once PHP actually implements this structure. As an alternative, what do you think about exposing this as part of the query string?
|
Depending on the parser you can also expose the PID as port number. |
I have created the most basic Unix server/client to test this feature with. Leaving it here for future reference. server.php
Note: after exiting the server you have to manually remove the client.php
Current output:
|
Small update: After some trial and error I think adding the PID to I feel like adding a separate method (like Another possibility is to create a new implementation of the Looking forward to hearing your thoughts. Regards, |
Following, I was about to enter a similar issue. |
@gdejong Thank you very much for looking into this!
Very good input, sounds reasonable.
I'm not entirely opposed to the idea, but looking at the suggest PR in #153 makes me wonder how this API is going to be consumed by downstream projects depending on this project. The As an alternative, how about we expose the stream resource in way so that downstream packages can use this to manually call this in their code? This can be as simple as this pseudo code: $connector->connect('unix://server.sock')->then(function (ConnectionInterface $conn) {
if (isset($conn->stream) && function_exists('stream_socket_import')) {
$socket = stream_socket_import($conn->stream);
$pid = socket_get_option($socket, SOL_SOCKET, SO_PEERCRED));
echo 'Connected to PID ' . $pid . PHP_EOL;
}
$conn->close();
}); |
Fair points, indeed interoperability could be a problem. I had actually already used your alternative. Currently that works well. The |
Currently when dealing with a
UnixServer
, its connections do not return a value forgetRemoteAddress
, the returned value is actuallyNULL
.I`d like it to return the PID of the connecting client. Is that something you would integrate in this library?
See http://php.net/manual/en/function.socket-get-option.php#101380
The text was updated successfully, but these errors were encountered: