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

Commit 95acfc8

Browse files
committed
Merge branch 'release/0.1.1' into develop
2 parents dd6c6c7 + 933b190 commit 95acfc8

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

src/Connection.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,19 @@ private function receive($len = null)
146146
/**
147147
* Returns an stream socket to the desired server.
148148
*
149-
* @param string $address Server url string.
150-
*
149+
* @param string $address Server url string.
150+
* @param integer $timeout Number of seconds until the connect() system call should timeout.
151151
* @return resource
152+
* @throws \Exception Exception raised if connection fails.
152153
*/
153-
private function getStream($address)
154+
private function getStream($address, $timeout = null)
154155
{
155-
$fp = stream_socket_client($address, $errno, $errstr, STREAM_CLIENT_CONNECT);
156+
if (is_null($timeout)) {
157+
$timeout = intval(ini_get('default_socket_timeout'));
158+
}
159+
$fp = stream_socket_client($address, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT);
156160
if (!$fp) {
157-
echo '!!!!!!! '.$errstr.' - '.$errno;
161+
throw new \Exception($errstr, $errno);
158162
}
159163
//stream_set_blocking($fp, 0);
160164
return $fp;
@@ -173,11 +177,13 @@ public function isConnected()
173177
/**
174178
* Connect to server.
175179
*
180+
* @param integer $timeout Number of seconds until the connect() system call should timeout.
181+
* @throws \Exception Exception raised if connection fails.
176182
* @return void
177183
*/
178-
public function connect()
184+
public function connect($timeout = null)
179185
{
180-
$this->streamSocket = $this->getStream($this->options->getAddress());
186+
$this->streamSocket = $this->getStream($this->options->getAddress(), $timeout);
181187
$msg = 'CONNECT '.$this->options;
182188
$this->send($msg);
183189
}
@@ -268,7 +274,7 @@ private function handleMSG($line)
268274
} else {
269275
return new \Exception('not callable');
270276
}
271-
277+
272278
return;
273279
}
274280

0 commit comments

Comments
 (0)