Skip to content
This repository was archived by the owner on Feb 5, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
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
28 changes: 25 additions & 3 deletions rdb/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,28 @@ class Connection extends DatumConverter
private $password;
private $activeTokens;
private $timeout;
private $connectTimeout;
private $ssl;

public $defaultDbName;

/**
* @param array|string $optsOrHost
* @param int $port
* @param string $db
* @param string $apiKey
* @param int $timeout
* @param int $connectTimeout
* @throws RqlDriverError
* @throws \Exception
*/
public function __construct(
$optsOrHost = null,
$port = null,
$db = null,
$apiKey = null,
$timeout = null
$timeout = null,
$connectTimeout = null
) {
if (is_array($optsOrHost)) {
$opts = $optsOrHost;
Expand Down Expand Up @@ -67,6 +79,9 @@ public function __construct(
if (isset($opts['timeout'])) {
$timeout = $opts['timeout'];
}
if (isset($opts['connectTimeout'])) {
$connectTimeout = $opts['connectTimeout'];
}
if (isset($opts['ssl'])) {
$ssl = $opts['ssl'];
}
Expand Down Expand Up @@ -106,6 +121,7 @@ public function __construct(
$this->user = $user;
$this->password = $password;
$this->timeout = null;
$this->connectTimeout = $connectTimeout ?: ini_get("default_socket_timeout");
$this->ssl = $ssl;

if (isset($db)) {
Expand Down Expand Up @@ -430,6 +446,10 @@ private function applyTimeout($timeout)
}
}

/**
* @throws RqlDriverError
* @throws \Exception
*/
private function connect()
{
if ($this->isOpen()) {
Expand All @@ -446,12 +466,14 @@ private function connect()
"ssl://" . $this->host . ":" . $this->port,
$errno,
$errstr,
ini_get("default_socket_timeout"),
$this->connectTimeout,
STREAM_CLIENT_CONNECT,
$context
);
} else {
$this->socket = stream_socket_client("tcp://" . $this->host . ":" . $this->port, $errno, $errstr);
$this->socket = stream_socket_client("tcp://" . $this->host . ":" . $this->port, $errno, $errstr,
$this->connectTimeout
);
}
if ($errno != 0 || $this->socket === false) {
$this->socket = null;
Expand Down
17 changes: 14 additions & 3 deletions rdb/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,20 @@

// ------------- Global functions in namespace r -------------

function connect($optsOrHost = null, $port = null, $db = null, $apiKey = null, $timeout = null)
{
return new Connection($optsOrHost, $port, $db, $apiKey, $timeout);
/**
* @param array|string $optsOrHost
* @param int $port
* @param string $db
* @param string $apiKey
* @param int $timeout
* @param int $connectTimeout
* @return Connection
* @throws RqlDriverError
* @throws \Exception
*/
function connect($optsOrHost = null, $port = null, $db = null, $apiKey = null, $timeout = null, $connectTimeout = null)
{
return new Connection($optsOrHost, $port, $db, $apiKey, $timeout, $connectTimeout);
}

function db($dbName)
Expand Down