From d46de81d9139d7175dee50192c5e4033b6f95873 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Thu, 30 Jul 2015 19:51:30 +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. --- 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 5bac88bb..946e25d6 100644 --- a/src/Connection/StreamConnection.php +++ b/src/Connection/StreamConnection.php @@ -152,7 +152,12 @@ class StreamConnection extends AbstractConnection */ protected function tcpStreamInitializer(ParametersInterface $parameters) { - $address = "tcp://[$parameters->host]:$parameters->port"; + if (!filter_var($parameters->host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { + $address = "tcp://$parameters->host:$parameters->port"; + } else { + $address = "tcp://[$parameters->host]:$parameters->port"; + } + $flags = STREAM_CLIENT_CONNECT; if (isset($parameters->async_connect) && $parameters->async_connect) {