/** * Given a single host, attempts to find other nodes in the cluster and attaches them * to the pool * @todo build connections from token map * @param string $host host name or IP of connecting node * @param string $poolName name of the connection pool (cluster name) * @param int $port TCP port of connecting node * @return bool connected ok */ public static function auto($host, $poolName = self::DEFAULT_POOL_NAME, $port = THRIFT_PORT_DEFAULT) { try { // Create Thrift transport and binary protocol cassandra client $transport = new TBufferedTransport(new TSocket($host, $port, PERSIST_CONNECTIONS, 'PandraCore::registerError'), 1024, 1024); $transport->open(); $client = new CassandraClient(function_exists("thrift_protocol_write_binary") ? new TBinaryProtocolAccelerated($transport) : new TBinaryProtocol($transport)); $tokenMap = $client->get_string_property('token map'); $tokens = json_decode($tokenMap); foreach ($tokens as $token => $host) { if (!self::connect($token, $host, $poolName)) { return FALSE; } } return TRUE; } catch (TException $te) { self::registerError('TException: ' . $te->getMessage() . ' ' . (isset($te->why) ? $te->why : '')); } return FALSE; }