From 2fc5ae4e6cb24b5944b60f9d18584f292f6aca98 Mon Sep 17 00:00:00 2001 From: Surfoo Date: Wed, 25 Sep 2019 20:19:22 +0200 Subject: [PATCH] Added catch ErrorException when neo4j is not up: [ErrorException] Warning: stream_socket_client(): unable to connect to tcp://localhost:7687 (Connection refused) --- src/IO/StreamSocket.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/IO/StreamSocket.php b/src/IO/StreamSocket.php index 0f127fc..702a3e4 100644 --- a/src/IO/StreamSocket.php +++ b/src/IO/StreamSocket.php @@ -194,14 +194,20 @@ public function connect() $this->port ); - $this->sock = stream_socket_client( - $remote, - $errno, - $errstr, - $this->timeout, - STREAM_CLIENT_CONNECT, - $this->context - ); + try { + $this->sock = stream_socket_client( + $remote, + $errno, + $errstr, + $this->timeout, + STREAM_CLIENT_CONNECT, + $this->context + ); + } catch(\ErrorException $e) { + throw new IOException(sprintf( + 'Error to connect to the server(%s) : "%s"', $errno, $errstr + )); + } if (false === $this->sock) { throw new IOException(sprintf(