Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit b39cf32

Browse files
committed
FEATURE: Add microseconds precision for timeout
1 parent e47b9fa commit b39cf32

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

src/Connection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function getSubscriptions()
9797
/**
9898
* Connection timeout
9999
*
100-
* @var integer
100+
* @var float
101101
*/
102102
private $timeout = null;
103103

@@ -187,7 +187,7 @@ private function receive($len = null)
187187
* Returns an stream socket to the desired server.
188188
*
189189
* @param string $address Server url string.
190-
* @param integer $timeout Number of seconds until the connect() system call should timeout.
190+
* @param float $timeout Number of seconds until the connect() system call should timeout.
191191
*
192192
* @return resource
193193
* @throws \Exception Exception raised if connection fails.
@@ -223,7 +223,7 @@ public function isConnected()
223223
/**
224224
* Connect to server.
225225
*
226-
* @param integer $timeout Number of seconds until the connect() system call should timeout.
226+
* @param float $timeout Number of seconds until the connect() system call should timeout.
227227
*
228228
* @throws \Exception Exception raised if connection fails.
229229
* @return void
@@ -436,7 +436,7 @@ public function wait($quantity = 0)
436436
/**
437437
* Set Stream Timeout.
438438
*
439-
* @param integer $seconds Before timeout on stream.
439+
* @param float $seconds Before timeout on stream.
440440
*
441441
* @return boolean
442442
*/

src/StreamWrapper.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,35 @@ class StreamWrapper
1010
/**
1111
* Wrapper for stream_socket_client
1212
*
13-
* @param string $address Address to connect the socket.
14-
* @param integer $errno Number of error.
15-
* @param string $errstr Description of error.
16-
* @param integer $timeout Timeout.
13+
* @param string $address Address to connect the socket.
14+
* @param integer $errno Number of error.
15+
* @param string $errstr Description of error.
16+
* @param float $timeout Timeout.
1717
* @param integer $typeStream Type of stream.
1818
*
1919
* @return resource
2020
*/
2121
public function getStreamSocketClient($address, &$errno, &$errstr, $timeout, $typeStream)
2222
{
2323
$stream = stream_socket_client($address, $errno, $errstr, $timeout, $typeStream);
24-
stream_set_timeout($stream, $timeout);
24+
$this->setStreamTimeout($stream, $timeout);
2525
return $stream;
2626
}
27-
27+
2828
/**
2929
* Wrapper for stream_set_timeout
3030
*
31-
* @param mixed $stream Stream.
32-
* @param integer $seconds Seconds for timeout.
31+
* @param mixed $stream Stream.
32+
* @param float $seconds Seconds for timeout.
3333
*
3434
* @return boolean
3535
*
36-
*/
36+
*/
3737
public function setStreamTimeout($stream, $seconds)
3838
{
39-
return stream_set_timeout($stream, $seconds);
39+
$timeout = number_format($seconds, 3);
40+
$seconds = floor($timeout);
41+
$microseconds = ($timeout - $seconds) * 1000;
42+
return stream_set_timeout($stream, $seconds, $microseconds);
4043
}
4144
}

0 commit comments

Comments
 (0)