From d4a7bd52bec23186b407d38947ec13909c093e4b Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Thu, 30 Jul 2015 20:23:45 +0200 Subject: [PATCH] Fix severe regression on HHVM. Apparently HHVM is more strict than PHP in stream_socket_client() and does not like at all IPv4 addresses and hostnames eclosed in square brackets. Note that it is not that weird as square brackets are mandatory only when IPv6 addresses are embedded in URI strings, so it is more like a weird incompatiblity of HHVM with the behaviour of the standard PHP interpreter. The connect() attempt fails but not due to the server being unavailable or some connectivity issue. The important lesson is: never rely on undocumented behaviours especially when targeting different runtimes, and do not forget to run the test suite on every platform right before release like I unfortunately did. This commit fixes #269. --- src/Connection/StreamConnection.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Connection/StreamConnection.php b/src/Connection/StreamConnection.php index 7bf3873c..ed6540b8 100644 --- a/src/Connection/StreamConnection.php +++ b/src/Connection/StreamConnection.php @@ -74,7 +74,12 @@ class StreamConnection extends AbstractConnection */ protected function tcpStreamInitializer(ParametersInterface $parameters) { - $uri = "tcp://[$parameters->host]:$parameters->port"; + if (!filter_var($parameters->host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { + $uri = "tcp://$parameters->host:$parameters->port"; + } else { + $uri = "tcp://[$parameters->host]:$parameters->port"; + } + $flags = STREAM_CLIENT_CONNECT; if (isset($parameters->async_connect) && (bool) $parameters->async_connect) {