Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Catch fatal exception in stream_socket_client
  • Loading branch information
valzargaming authored Oct 24, 2025
commit 4edc68ef1a59d4096a34de3054ec00636ffe636f
23 changes: 15 additions & 8 deletions src/TcpConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,21 @@ public function connect($uri)
// HHVM fails to parse URIs with a query but no path, so let's simplify our URI here
$remote = 'tcp://' . $parts['host'] . ':' . $parts['port'];

$stream = @\stream_socket_client(
$remote,
$errno,
$errstr,
0,
\STREAM_CLIENT_CONNECT | \STREAM_CLIENT_ASYNC_CONNECT,
\stream_context_create($context)
);
try {
$stream = @\stream_socket_client(
$remote,
$errno,
$errstr,
0,
\STREAM_CLIENT_CONNECT | \STREAM_CLIENT_ASYNC_CONNECT,
\stream_context_create($context)
);
} catch (\Exception $e) {
return Promise\reject(new \RuntimeException(
'Connection to ' . $uri . ' failed: ' . $errstr . SocketServer::errconst($errno),
$errno
));
}

if (false === $stream) {
return Promise\reject(new \RuntimeException(
Expand Down