From cbe84735a679f8e15e7dd702f0443be450c31f70 Mon Sep 17 00:00:00 2001 From: Fabiano Simoes Date: Fri, 16 Jan 2015 16:18:38 -0200 Subject: [PATCH 01/12] Resolved issue with null bytes from Cassandra. --- src/Protocol/Response/DataStream.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Protocol/Response/DataStream.php b/src/Protocol/Response/DataStream.php index 55a8c31..951a29a 100644 --- a/src/Protocol/Response/DataStream.php +++ b/src/Protocol/Response/DataStream.php @@ -174,6 +174,12 @@ public function readBytes($isCollectionElement = false) { if ($isCollectionElement) $this->readShort(); $length = $this->readInt(); + + if ($length === -1) + { + return null; + } + return $this->read($length); } From 6ad55d9c9ac57de90f2eca44e86be492bd941278 Mon Sep 17 00:00:00 2001 From: Fabiano Simoes Date: Wed, 21 Jan 2015 14:28:49 -0200 Subject: [PATCH 02/12] Fixed reading NULL data for bigint data type. --- src/Protocol/Response/DataStream.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Protocol/Response/DataStream.php b/src/Protocol/Response/DataStream.php index 951a29a..1be5568 100644 --- a/src/Protocol/Response/DataStream.php +++ b/src/Protocol/Response/DataStream.php @@ -36,6 +36,10 @@ public function __construct($binary) { * @return string */ protected function read($length) { + if ( ! $length) { + return null; + } + if ($this->length < $length) { throw new \Exception('Reading while at end of stream'); } From fb6b7c49aafe2bc31c6dd345f8d483a50d003efb Mon Sep 17 00:00:00 2001 From: Fabiano Simoes Date: Fri, 23 Jan 2015 13:42:19 -0200 Subject: [PATCH 03/12] Added new feature to choose node connection in a random or sequential way. --- README.md | 4 ++++ src/Cluster.php | 11 +++++++++-- src/Connection.php | 10 ++++++++-- src/Database.php | 4 ++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1b05ca6..c8f7de7 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,13 @@ Cassandra client library for PHP, using the native binary protocol. * decimal and timestamps have bugs especially in collections (map,set,list) * connection handling e.g. timeouts +## New feature for this fork +* on Database class constructor, now you can choose whether you want to connect to your nodes randomically or sequentially + ## Installation PHP 5.4+ is required. There is no need for additional libraries. +PHP Sockets extension is required to use Cassandra's binary protocol. Append dependency into composer.json diff --git a/src/Cluster.php b/src/Cluster.php index 8e579c9..9de4b84 100644 --- a/src/Cluster.php +++ b/src/Cluster.php @@ -28,9 +28,16 @@ public function appendNode($host) { * @return Node * @throws Exception\ClusterException */ - public function getRandomNode() { + public function getNode($random = FALSE) { if (empty($this->nodes)) throw new ClusterException('Node list is empty.'); - $nodeKey = array_rand($this->nodes); + + if ($random) { + $nodeKey = array_rand($this->nodes); + } + else { + $nodeKey = array_keys($this->nodes)[0]; + } + $node = $this->nodes[$nodeKey]; try { if ((array)$node === $node) { diff --git a/src/Connection.php b/src/Connection.php index 741ad9c..82c6fa4 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -14,6 +14,11 @@ class Connection { */ private $cluster; + /** + * @var UseRandomNOdes + */ + private $useRandomNodes; + /** * @var Node */ @@ -27,13 +32,14 @@ class Connection { /** * @param Cluster $cluster */ - public function __construct(Cluster $cluster) { + public function __construct(Cluster $cluster, $useRandomNodes) { $this->cluster = $cluster; + $this->useRandomNodes = $useRandomNodes; } public function connect() { try { - $this->node = $this->cluster->getRandomNode(); + $this->node = $this->cluster->getNode($this->useRandomNodes); $this->connection = $this->node->getConnection(); } catch (ConnectionException $e) { $this->connect(); diff --git a/src/Database.php b/src/Database.php index 086d4a0..cd21a70 100644 --- a/src/Database.php +++ b/src/Database.php @@ -50,9 +50,9 @@ class Database { * @param string $keyspace * @param array $options */ - public function __construct(array $nodes, $keyspace = '', array $options = []) { + public function __construct(array $nodes, $keyspace = '', array $options = [], $useRandomNodes = TRUE) { $this->cluster = new Cluster($nodes); - $this->connection = new Connection($this->cluster); + $this->connection = new Connection($this->cluster, $useRandomNodes); $this->options = array_merge($this->options, $options); $this->keyspace = $keyspace; } From 2aa270e5cfec8e50dee24a358f3093fa1611ade4 Mon Sep 17 00:00:00 2001 From: Fabiano Simoes Date: Wed, 28 Jan 2015 11:29:59 -0200 Subject: [PATCH 04/12] Added socket_close after socket_shutdown. This will properly close the connection with Cassandra. --- src/Connection.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Connection.php b/src/Connection.php index 82c6fa4..f7d24ea 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -50,7 +50,9 @@ public function connect() { * @return bool */ public function disconnect() { - return socket_shutdown($this->connection); + $socketShutdown = socket_shutdown($this->connection); + socket_close($this->connection); + return $socketShutdown; } /** From 5da0f54520d188332e4f256f98772a6f70a4378b Mon Sep 17 00:00:00 2001 From: Fabiano Simoes Date: Thu, 12 Feb 2015 12:36:12 -0200 Subject: [PATCH 05/12] Added a recover procedure using socket block/unblock to avoid timeout bug with socket_connect. Now you can correctly control the socket timeout and the attempts to connect to server. --- src/Cluster.php | 15 ++++++++++++++- src/Cluster/Node.php | 38 ++++++++++++++++++++++++++++++++++++-- src/Connection.php | 23 ++++++++++++++++++++++- src/Database.php | 7 +++++++ 4 files changed, 79 insertions(+), 4 deletions(-) diff --git a/src/Cluster.php b/src/Cluster.php index 9de4b84..ae2d171 100644 --- a/src/Cluster.php +++ b/src/Cluster.php @@ -10,6 +10,11 @@ class Cluster { */ private $nodes; + /** + * @var array + */ + private $usedNodes; + /** * @param array $nodes */ @@ -29,7 +34,11 @@ public function appendNode($host) { * @throws Exception\ClusterException */ public function getNode($random = FALSE) { - if (empty($this->nodes)) throw new ClusterException('Node list is empty.'); + if (empty($this->nodes)) { + $this->nodes = $this->usedNodes; + $this->usedNodes = array(); + throw new ClusterException('Node list is empty.'); + } if ($random) { $nodeKey = array_rand($this->nodes); @@ -39,14 +48,18 @@ public function getNode($random = FALSE) { } $node = $this->nodes[$nodeKey]; + try { if ((array)$node === $node) { + $this->usedNodes[$nodeKey] = $node; $node = new Node($nodeKey, $node); unset($this->nodes[$nodeKey]); } else { + $this->usedNodes[$nodeKey] = $node; $node = new Node($node); unset($this->nodes[$nodeKey]); } + } catch (\InvalidArgumentException $e) { trigger_error($e->getMessage()); } diff --git a/src/Cluster/Node.php b/src/Cluster/Node.php index dbe8808..fc56720 100644 --- a/src/Cluster/Node.php +++ b/src/Cluster/Node.php @@ -55,12 +55,39 @@ public function getConnection() { if (!empty($this->socket)) return $this->socket; $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); + socket_set_option($this->socket, getprotobyname('TCP'), TCP_NODELAY, 1); socket_set_option($this->socket, SOL_SOCKET, SO_RCVTIMEO, ["sec" => self::STREAM_TIMEOUT, "usec" => 0]); - if (!socket_connect($this->socket, $this->host, $this->port)) { - throw new ConnectionException("Unable to connect to Cassandra node: {$this->host}:{$this->port}"); + socket_set_nonblock($this->socket); + + $time = time(); + $timeout = 1; // seconds + + // Loop until a connection is successfully made or timeout reached + while (!@socket_connect($this->socket, $this->host, $this->port)) { + $err = socket_last_error($this->socket); + + // Connection OK! + if($err === 10056) { + break; + } + + // If we reach timeout, throw exception and exit. + if ((time() - $time) >= $timeout) { + + socket_set_block($this->socket); + socket_close($this->socket); + info('Timeout reached! Unable to connect to ' . $this->host . ' on port ' . $this->port); + throw new ConnectionException("Unable to connect to Cassandra node."); + } + + // 250 ms sleeping time to waitNo the next attempt. + usleep(250000); } + // Re-block the socket if needed + socket_set_block($this->socket); + return $this->socket; } @@ -70,4 +97,11 @@ public function getConnection() { public function getOptions() { return $this->options; } + + /** + * @return string + */ + public function getHost() { + return $this->host; + } } \ No newline at end of file diff --git a/src/Connection.php b/src/Connection.php index f7d24ea..9934c69 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -14,6 +14,16 @@ class Connection { */ private $cluster; + /** + * @var int + */ + private $connMaxAttempts; + + /** + * @var int + */ + private $connAttempts; + /** * @var UseRandomNOdes */ @@ -35,12 +45,23 @@ class Connection { public function __construct(Cluster $cluster, $useRandomNodes) { $this->cluster = $cluster; $this->useRandomNodes = $useRandomNodes; + $this->connMaxAttempts = 30; + $this->connAttempts = 0; } public function connect() { + try { $this->node = $this->cluster->getNode($this->useRandomNodes); $this->connection = $this->node->getConnection(); + } catch (Exception\ClusterException $e) { + if ($this->connAttempts >= $this->connMaxAttempts) + { + return; + } + + $this->connAttempts++; + $this->connect(); } catch (ConnectionException $e) { $this->connect(); } @@ -78,7 +99,7 @@ public function sendRequest(Request $request) { * @return string */ private function fetchData($length) { - $data = socket_read($this->connection, $length); + $data = @socket_read($this->connection, $length); while (strlen($data) < $length) { $data .= socket_read($this->connection, $length); } diff --git a/src/Database.php b/src/Database.php index cd21a70..f3ac7a1 100644 --- a/src/Database.php +++ b/src/Database.php @@ -65,7 +65,14 @@ public function __construct(array $nodes, $keyspace = '', array $options = [], $ */ public function connect() { if ($this->connection->isConnected()) return true; + $this->connection->connect(); + + if (!$this->connection->isConnected()) + { + return false; + } + $response = $this->connection->sendRequest( RequestFactory::startup($this->options) ); From 1b4019101b8465de1bca29bdc48e39a1dfab0b71 Mon Sep 17 00:00:00 2001 From: Fabiano Simoes Date: Fri, 13 Feb 2015 16:08:40 -0200 Subject: [PATCH 06/12] Skip php warnings in socket_read when reading data from socket. --- src/Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Connection.php b/src/Connection.php index 9934c69..eb316d2 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -101,7 +101,7 @@ public function sendRequest(Request $request) { private function fetchData($length) { $data = @socket_read($this->connection, $length); while (strlen($data) < $length) { - $data .= socket_read($this->connection, $length); + $data .= @socket_read($this->connection, $length); } if (socket_last_error($this->connection) == 110) { throw new ConnectionException('Connection timed out'); From 7e32e9d6eab84d60023df781496390257c1f0eee Mon Sep 17 00:00:00 2001 From: Fabiano Simoes Date: Wed, 18 Feb 2015 17:16:33 -0200 Subject: [PATCH 07/12] Fixed infinite loop on connection. Now we throw an Exception if the max attempts are reached. --- src/Connection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index eb316d2..6029330 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -45,7 +45,7 @@ class Connection { public function __construct(Cluster $cluster, $useRandomNodes) { $this->cluster = $cluster; $this->useRandomNodes = $useRandomNodes; - $this->connMaxAttempts = 30; + $this->connMaxAttempts = 3; $this->connAttempts = 0; } @@ -57,7 +57,7 @@ public function connect() { } catch (Exception\ClusterException $e) { if ($this->connAttempts >= $this->connMaxAttempts) { - return; + throw new ConnectionException('I tried to connect to Database ' . $this->connMaxAttempts . ' times with no response.'); } $this->connAttempts++; From b81a9aa305c7deeb88776e168ae467c432e47ca5 Mon Sep 17 00:00:00 2001 From: Fabiano Simoes Date: Sun, 1 Mar 2015 18:13:54 -0300 Subject: [PATCH 08/12] Fixed Consistency Level LOCAL_ONE error message. The correct value is 0xA. --- src/Connection.php | 2 +- src/Enum/ConsistencyEnum.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index 6029330..3fff4ee 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -45,7 +45,7 @@ class Connection { public function __construct(Cluster $cluster, $useRandomNodes) { $this->cluster = $cluster; $this->useRandomNodes = $useRandomNodes; - $this->connMaxAttempts = 3; + $this->connMaxAttempts = 2; $this->connAttempts = 0; } diff --git a/src/Enum/ConsistencyEnum.php b/src/Enum/ConsistencyEnum.php index d80ccb7..d9a4dbb 100644 --- a/src/Enum/ConsistencyEnum.php +++ b/src/Enum/ConsistencyEnum.php @@ -10,5 +10,5 @@ class ConsistencyEnum { const CONSISTENCY_ALL = 0x0005; const CONSISTENCY_LOCAL_QUORUM = 0x0006; const CONSISTENCY_EACH_QUORUM = 0x0007; - const CONSISTENCY_LOCAL_ONE = 0x0010; + const CONSISTENCY_LOCAL_ONE = 0xA; } \ No newline at end of file From d912c9f88fd9fa3a788cb6dbb22902861a85ef49 Mon Sep 17 00:00:00 2001 From: Julien Colomb Date: Fri, 13 Mar 2015 19:24:48 -0300 Subject: [PATCH 09/12] update sockect connection --- src/Cluster.php | 8 ++++++-- src/Cluster/Node.php | 34 +++++++++++++++++++++------------- src/Connection.php | 14 ++++++++++---- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/Cluster.php b/src/Cluster.php index ae2d171..1a5be4e 100644 --- a/src/Cluster.php +++ b/src/Cluster.php @@ -29,14 +29,17 @@ public function appendNode($host) { $this->nodes[] = $host; } + public function resetNodes() { + $this->nodes = $this->usedNodes; + $this->usedNodes = array(); + } + /** * @return Node * @throws Exception\ClusterException */ public function getNode($random = FALSE) { if (empty($this->nodes)) { - $this->nodes = $this->usedNodes; - $this->usedNodes = array(); throw new ClusterException('Node list is empty.'); } @@ -55,6 +58,7 @@ public function getNode($random = FALSE) { $node = new Node($nodeKey, $node); unset($this->nodes[$nodeKey]); } else { + $this->usedNodes[$nodeKey] = $node; $this->usedNodes[$nodeKey] = $node; $node = new Node($node); unset($this->nodes[$nodeKey]); diff --git a/src/Cluster/Node.php b/src/Cluster/Node.php index fc56720..c13e381 100644 --- a/src/Cluster/Node.php +++ b/src/Cluster/Node.php @@ -52,7 +52,8 @@ public function __construct($host, array $options = []) { * @throws \Exception */ public function getConnection() { - if (!empty($this->socket)) return $this->socket; + + if ( ! empty($this->socket)) return $this->socket; $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); @@ -60,29 +61,36 @@ public function getConnection() { socket_set_option($this->socket, SOL_SOCKET, SO_RCVTIMEO, ["sec" => self::STREAM_TIMEOUT, "usec" => 0]); socket_set_nonblock($this->socket); - $time = time(); - $timeout = 1; // seconds + debug("Attempt to connect to cassandra {$this->host}:{$this->port}"); + + $time = microtime(); + + while ( ! @socket_connect($this->socket, $this->host, $this->port)) { - // Loop until a connection is successfully made or timeout reached - while (!@socket_connect($this->socket, $this->host, $this->port)) { $err = socket_last_error($this->socket); // Connection OK! - if($err === 10056) { + if ($err === 10056 || $err === 56) { break; } - // If we reach timeout, throw exception and exit. - if ((time() - $time) >= $timeout) { + // 61: server found but port unavailable (connection refused) + // 37: ip does not exist, i wait + if ($err === 10061 || $err === 61 || $err === 37 || $err === 10037) { + socket_close($this->socket); + + throw new ConnectionException('unable to connect code : ' . $err); + } + + // if timeout reaches then call exit(); + if ((microtime() - $time) >= 1000000) { - socket_set_block($this->socket); socket_close($this->socket); - info('Timeout reached! Unable to connect to ' . $this->host . ' on port ' . $this->port); - throw new ConnectionException("Unable to connect to Cassandra node."); + + throw new ConnectionException('unable to connect code (connection timeout) : ' . $err); } - // 250 ms sleeping time to waitNo the next attempt. - usleep(250000); + usleep(100000); } // Re-block the socket if needed diff --git a/src/Connection.php b/src/Connection.php index 3fff4ee..28d2298 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -52,17 +52,23 @@ public function __construct(Cluster $cluster, $useRandomNodes) { public function connect() { try { + $this->node = $this->cluster->getNode($this->useRandomNodes); $this->connection = $this->node->getConnection(); + + } catch (ConnectionException $e) { + $this->connect(); + } catch (Exception\ClusterException $e) { - if ($this->connAttempts >= $this->connMaxAttempts) - { + + if ($this->connAttempts >= $this->connMaxAttempts) { throw new ConnectionException('I tried to connect to Database ' . $this->connMaxAttempts . ' times with no response.'); } $this->connAttempts++; - $this->connect(); - } catch (ConnectionException $e) { + + $this->cluster->resetNodes(); + $this->connect(); } } From 425f66565424a4e309cb58ea1a7813861dafca2c Mon Sep 17 00:00:00 2001 From: Fabiano Simoes Date: Tue, 24 Mar 2015 17:18:26 -0300 Subject: [PATCH 10/12] Fix issue with timeout on socket_connect. Timeout was converted to attempts. Code clarified to a better reading. Added a more precise error control over socket error codes. This will avoid php process being hanged when no server is available. --- src/Cluster.php | 42 +++++++++++++++++++++++++--------- src/Cluster/Node.php | 54 +++++++++++++++++++++++++------------------- src/Connection.php | 5 ++-- 3 files changed, 64 insertions(+), 37 deletions(-) diff --git a/src/Cluster.php b/src/Cluster.php index 1a5be4e..b6afd3d 100644 --- a/src/Cluster.php +++ b/src/Cluster.php @@ -18,14 +18,16 @@ class Cluster { /** * @param array $nodes */ - public function __construct(array $nodes = []) { + public function __construct(array $nodes = []) + { $this->nodes = $nodes; } /** * @param string $host */ - public function appendNode($host) { + public function appendNode($host) + { $this->nodes[] = $host; } @@ -34,37 +36,55 @@ public function resetNodes() { $this->usedNodes = array(); } + /** + * Reset used nodes list. + */ + public function resetNodes() + { + $this->nodes = $this->usedNodes; + $this->usedNodes = array(); + } + /** * @return Node * @throws Exception\ClusterException */ - public function getNode($random = FALSE) { - if (empty($this->nodes)) { + public function getNode($random = FALSE) + { + if (empty($this->nodes)) + { throw new ClusterException('Node list is empty.'); } - if ($random) { + if ($random) + { $nodeKey = array_rand($this->nodes); } - else { + else + { $nodeKey = array_keys($this->nodes)[0]; } $node = $this->nodes[$nodeKey]; - try { - if ((array)$node === $node) { + try + { + if ((array)$node === $node) + { $this->usedNodes[$nodeKey] = $node; $node = new Node($nodeKey, $node); unset($this->nodes[$nodeKey]); - } else { - $this->usedNodes[$nodeKey] = $node; + } + else + { $this->usedNodes[$nodeKey] = $node; $node = new Node($node); unset($this->nodes[$nodeKey]); } - } catch (\InvalidArgumentException $e) { + } + catch (\InvalidArgumentException $e) + { trigger_error($e->getMessage()); } diff --git a/src/Cluster/Node.php b/src/Cluster/Node.php index c13e381..12a0db3 100644 --- a/src/Cluster/Node.php +++ b/src/Cluster/Node.php @@ -3,9 +3,10 @@ use evseevnn\Cassandra\Exception\ConnectionException; -class Node { +class Node +{ - const STREAM_TIMEOUT = 10; + const STREAM_TIMEOUT = 2; /** * @var string @@ -35,15 +36,19 @@ class Node { * @param array $options * @throws \InvalidArgumentException */ - public function __construct($host, array $options = []) { + public function __construct($host, array $options = []) + { $this->host = $host; - if (strstr($this->host, ':')) { + if (strstr($this->host, ':')) + { $this->port = (int)substr(strstr($this->host, ':'), 1); $this->host = substr($this->host, 0, -1 - strlen($this->port)); - if (!$this->port) { + if (!$this->port) + { throw new \InvalidArgumentException('Invalid port number'); } } + $this->options = array_merge($this->options, $options); } @@ -51,8 +56,8 @@ public function __construct($host, array $options = []) { * @return resource * @throws \Exception */ - public function getConnection() { - + public function getConnection() + { if ( ! empty($this->socket)) return $this->socket; $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); @@ -61,33 +66,34 @@ public function getConnection() { socket_set_option($this->socket, SOL_SOCKET, SO_RCVTIMEO, ["sec" => self::STREAM_TIMEOUT, "usec" => 0]); socket_set_nonblock($this->socket); - debug("Attempt to connect to cassandra {$this->host}:{$this->port}"); - - $time = microtime(); - - while ( ! @socket_connect($this->socket, $this->host, $this->port)) { + $maxAttempts = 3; + $attempts = 0; - $err = socket_last_error($this->socket); + while ( ! @socket_connect($this->socket, $this->host, $this->port)) + { + $attempts++; + $err = substr(socket_last_error($this->socket), -2); // Connection OK! - if ($err === 10056 || $err === 56) { + if ($err === "56") + { break; } // 61: server found but port unavailable (connection refused) // 37: ip does not exist, i wait - if ($err === 10061 || $err === 61 || $err === 37 || $err === 10037) { + // 01: host not found + if ($err === "61" || $err === "37" || $err === "01") + { socket_close($this->socket); - - throw new ConnectionException('unable to connect code : ' . $err); + throw new ConnectionException('Unable to connect. Socket last error code : ' . $err); } // if timeout reaches then call exit(); - if ((microtime() - $time) >= 1000000) { - + if ($attempts > $maxAttempts) + { socket_close($this->socket); - - throw new ConnectionException('unable to connect code (connection timeout) : ' . $err); + throw new ConnectionException('Unable to connect. Socket last error code (connection timeout) : ' . $err); } usleep(100000); @@ -102,14 +108,16 @@ public function getConnection() { /** * @return array */ - public function getOptions() { + public function getOptions() + { return $this->options; } /** * @return string */ - public function getHost() { + public function getHost() + { return $this->host; } } \ No newline at end of file diff --git a/src/Connection.php b/src/Connection.php index 28d2298..deaae7d 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -61,14 +61,13 @@ public function connect() { } catch (Exception\ClusterException $e) { - if ($this->connAttempts >= $this->connMaxAttempts) { + if ($this->connAttempts >= $this->connMaxAttempts) + { throw new ConnectionException('I tried to connect to Database ' . $this->connMaxAttempts . ' times with no response.'); } $this->connAttempts++; - $this->cluster->resetNodes(); - $this->connect(); } } From bac11f967638b31994b6d718f5ea3ffe22f828d4 Mon Sep 17 00:00:00 2001 From: Fabiano Simoes Date: Tue, 24 Mar 2015 19:18:21 -0300 Subject: [PATCH 11/12] Fix mistake. --- src/Cluster.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Cluster.php b/src/Cluster.php index b6afd3d..45e5788 100644 --- a/src/Cluster.php +++ b/src/Cluster.php @@ -31,11 +31,6 @@ public function appendNode($host) $this->nodes[] = $host; } - public function resetNodes() { - $this->nodes = $this->usedNodes; - $this->usedNodes = array(); - } - /** * Reset used nodes list. */ From 2222c1dab47910546e09c1b1e9d9ed0b6d58ed28 Mon Sep 17 00:00:00 2001 From: Fabiano Simoes Date: Fri, 27 Mar 2015 11:57:44 -0300 Subject: [PATCH 12/12] Removed check for code 37 on socket_connect --- src/Cluster/Node.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cluster/Node.php b/src/Cluster/Node.php index 12a0db3..2773f67 100644 --- a/src/Cluster/Node.php +++ b/src/Cluster/Node.php @@ -83,7 +83,7 @@ public function getConnection() // 61: server found but port unavailable (connection refused) // 37: ip does not exist, i wait // 01: host not found - if ($err === "61" || $err === "37" || $err === "01") + if ($err === "61" || $err === "01") { socket_close($this->socket); throw new ConnectionException('Unable to connect. Socket last error code : ' . $err);