/** * */ protected function refreshConnections() { if (is_null($this->lookup)) { return; } $this->host_list = $this->lookup->lookup(); // add new connections foreach ($this->host_list as $host) { $host_flag = false; $host_info = explode(':', $host); foreach ($this->connections as $conn) { if ($conn->equal($host_info[0], $host_info[1])) { $host_flag = true; } } if ($host_flag === false) { array_push($this->connections, new Connection($host_info[0], $host_info[1])); } } // remove connections foreach ($this->connections as $key => $conn) { $conn_flag = false; foreach ($this->host_list as $host) { $host_info = explode(':', $host); if ($conn->equal($host_info[0], $host_info[1])) { $conn_flag = true; } } if ($conn_flag === false) { $conn->close(); unset($this->connections[$key]); } } }
protected function addLookupTimer() { $this->loop->addPeriodicTimer(30, function () { $addresses = $this->lookup->lookup(); foreach ($addresses as $address) { $key = $address['ip'] . ':' . $address['port']; } // ... refresh connection }); }
public function testClusterLookup() { $hosts = $this->lookup_cluster->lookup(); $this->assertEquals($hosts[0], "waytoft:4150"); }