clue · GitHub

This is all covered by the test suite and we now make sure to either return the correct address string or null if it's unknown. Here's how this works under the hood:

>>> $f = stream_socket_client('google.com:80');
=> stream resource #279
>>> stream_socket_get_name($f, true);
=> "216.58.205.238:80"
>>> fclose($f);
=> true
>>> @stream_socket_get_name($f, true);
PHP warning:  stream_socket_get_name(): supplied resource is not a valid stream resource on line 1
=> false
>>> @stream_socket_get_name(false, true);
PHP warning:  stream_socket_get_name() expects parameter 1 to be resource, boolean given on line 1
=> false

This uses a client socket for simplicity, the server socket emits similar errors but has far more error situations, e.g. the server socket does not have a remote address and returns false without emitting an error (unless you're on HHVM).

Read the original on github.com ↗