Skip to content

Commit 926fc34

Browse files
author
Alexey Gavrilov
committed
add timeout period on stream support
1 parent 1938142 commit 926fc34

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

DnodeSyncClient.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,20 @@ class Dnode {
4343
*
4444
* @param string $host
4545
* @param string $port
46-
* @param float $connectTimeout Number of seconds until `connect()` should timeout.
46+
* @param bool|float $connectTimeout Number of seconds until `connect()` should timeout.
4747
* Default: `ini_get("default_socket_timeout")`
4848
*
49-
* @return \DnodeSyncClient\Connection
50-
*
51-
* @throws \DnodeSyncClient\IOException
52-
* @throws \DnodeSyncClient\ProtocolException
49+
* @param bool $timeout
50+
* @return Connection
5351
*/
54-
public function connect($host, $port, $connectTimeout = false) {
52+
public function connect($host, $port, $connectTimeout = false, $timeout = false) {
5553
$address = "tcp://$host:$port";
5654
$stream = $connectTimeout ?
5755
@\stream_socket_client($address, $error, $errorMessage, $connectTimeout) :
5856
@\stream_socket_client($address, $error, $errorMessage);
57+
if ($timeout) {
58+
stream_set_timeout($stream, $timeout);
59+
}
5960
if (!$stream) {
6061
throw new IOException("Can't create socket to $address. Error: $error $errorMessage");
6162
}

0 commit comments

Comments
 (0)