/** * Open the transport for reading/writing * * @throws TTransportException if cannot open */ public function open() { if (!$this->isOpen()) { $this->transport_->open(); } $mechanism = 'PLAIN'; $header = pack('CN', self::START, strlen($mechanism)); $this->transport_->write($header . $mechanism); $username = '******'; $password = '******'; #密码为空随便写1个 不要传空字符串 $body = chr(0) . $username . chr(0) . $password; $header = pack('CN', self::COMPLETE, strlen($body)); $this->transport_->write($header . $body); $data = $this->transport_->readAll(5); $array = unpack('Cstatus/Ilength', $data); if ($array['status'] != self::COMPLETE) { throw new TTransportException(); } return true; }
public function open() { $this->transport_->open(); }
private function _openTransport() { if (!$this->transport->isOpen()) { $this->transport->open(); } }
/** * Constructs the connection, setting access parameters. * * @param string $host Hostname or IP of the node * @param integer $port Port of the instance * @param boolean $useFramedTransport Use framed or buffered transport * @param integer $sendTimeoutMs Timeout of send operations in milliseconds * @param integer $receiveTimeoutMs Timeout of receive operations */ public function __construct($host = '127.0.0.1', $port = 9160, $useFramedTransport = true, $sendTimeoutMs = null, $receiveTimeoutMs = null) { $this->host = $host; $this->port = $port; $this->useFramedTransport = $useFramedTransport; $this->sendTimeoutMs = $sendTimeoutMs; $this->receiveTimeoutMs = $receiveTimeoutMs; $this->isOpen = false; $this->socket = $this->createSocket($host, $port, $sendTimeoutMs, $receiveTimeoutMs); if ($useFramedTransport) { $this->transport = $this->createFramedTransport($this->socket); } else { $this->transport = $this->createBufferedTransport($this->socket); } $this->transport->open(); $this->isOpen = true; $this->protocol = new TBinaryProtocolAccelerated($this->transport); $this->client = new cassandra_CassandraClient($this->protocol); }