Inheritance: implements CassandraIf
Esempio n. 1
0
 public function __construct($keyspace, $server, $credentials, $framed_transport, $send_timeout, $recv_timeout)
 {
     $host = $server['host'];
     $port = $server['port'];
     $socket = new TSocket($host, $port);
     if ($send_timeout) {
         $socket->setSendTimeout($send_timeout);
     }
     if ($recv_timeout) {
         $socket->setRecvTimeout($recv_timeout);
     }
     if ($framed_transport) {
         $transport = new TFramedTransport($socket, true, true);
     } else {
         $transport = new TBufferedTransport($socket, 1024, 1024);
     }
     $client = new CassandraClient(new TBinaryProtocolAccelerated($transport));
     $transport->open();
     # TODO check API major version match
     $client->set_keyspace($keyspace);
     if ($credentials) {
         $request = cassandra_AuthenticationRequest($credentials);
         $client->login($request);
     }
     $this->keyspace = $keyspace;
     $this->client = $client;
     $this->transport = $transport;
 }
Esempio n. 2
0
 public function __construct($keyspace, $server, $credentials = null, $framed_transport = True, $send_timeout = null, $recv_timeout = null)
 {
     $this->server = $server;
     $server = explode(':', $server);
     $host = $server[0];
     if (count($server) == 2) {
         $port = (int) $server[1];
     } else {
         $port = self::DEFAULT_PORT;
     }
     $socket = new TSocket($host, $port);
     if ($send_timeout) {
         $socket->setSendTimeout($send_timeout);
     }
     if ($recv_timeout) {
         $socket->setRecvTimeout($recv_timeout);
     }
     if ($framed_transport) {
         $transport = new TFramedTransport($socket, true, true);
     } else {
         $transport = new TBufferedTransport($socket, 1024, 1024);
     }
     $client = new CassandraClient(new TBinaryProtocolAccelerated($transport));
     $transport->open();
     $server_version = explode(".", $client->describe_version());
     $server_version = $server_version[0];
     if ($server_version < self::LOWEST_COMPATIBLE_VERSION) {
         $ver = self::LOWEST_COMPATIBLE_VERSION;
         throw new IncompatibleAPIException("The server's API version is too " . "low to be comptible with phpcassa (server: {$server_version}, " . "lowest compatible version: {$ver})");
     }
     $client->set_keyspace($keyspace);
     if ($credentials) {
         $request = new cassandra_AuthenticationRequest(array("credentials" => $credentials));
         $client->login($request);
     }
     $this->keyspace = $keyspace;
     $this->client = $client;
     $this->transport = $transport;
     $this->op_count = 0;
 }
Esempio n. 3
0
 /**
  * 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;
 }
Esempio n. 4
0
 public function __construct($keyspace, $server, $credentials, $framed_transport, $send_timeout, $recv_timeout)
 {
     $host = $server['host'];
     $port = $server['port'];
     $socket = new TSocket($host, $port);
     if ($send_timeout) {
         $socket->setSendTimeout($send_timeout);
     }
     if ($recv_timeout) {
         $socket->setRecvTimeout($recv_timeout);
     }
     if ($framed_transport) {
         $transport = new TFramedTransport($socket, true, true);
     } else {
         $transport = new TBufferedTransport($socket, 1024, 1024);
     }
     $client = new CassandraClient(new TBinaryProtocolAccelerated($transport));
     $transport->open();
     # TODO check API major version match
     $server_version = explode(".", $client->describe_version());
     $server_version = $server_version[0];
     if ($server_version < self::LOWEST_COMPATIBLE_VERSION) {
         $ver = self::LOWEST_COMPATIBLE_VERSION;
         throw new IncompatbleAPIException("The server's API version is too " . "low to be comptible with phpcassa (server: {$server_version}, " . "lowest compatible version: {$ver})");
     }
     $client->set_keyspace($keyspace);
     if ($credentials) {
         $request = cassandra_AuthenticationRequest($credentials);
         $client->login($request);
     }
     $this->keyspace = $keyspace;
     $this->client = $client;
     $this->transport = $transport;
 }
<?php

$GLOBALS['THRIFT_ROOT'] = '/usr/share/php/Thrift';
require_once $GLOBALS['THRIFT_ROOT'] . '/packages/cassandra/Cassandra.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/packages/cassandra/cassandra_types.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TFramedTransport.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TBufferedTransport.php';
try {
    // Make a connection to the Thrift interface to Cassandra
    $socket = new TSocket('127.0.0.1', 9160);
    $transport = new TBufferedTransport($socket, 1024, 1024);
    $protocol = new TBinaryProtocolAccelerated($transport);
    $client = new CassandraClient($protocol);
    $transport->open();
    /* Insert some data into the Standard1 column family from the default config */
    // Keyspace specified in storage=conf.xml
    $keyspace = 'Keyspace1';
    // reference to specific User id
    $keyUserId = "1";
    // Constructing the column path that we are adding information into.
    $columnPath = new cassandra_ColumnPath();
    $columnPath->column_family = 'Standard1';
    $columnPath->super_column = null;
    $columnPath->column = 'email';
    // Timestamp for update
    $timestamp = time();
    // We want the consistency level to be ZERO which means async operations on 1 node
    $consistency_level = cassandra_ConsistencyLevel::ZERO;
    // Add the value to be written to the table, User Key, and path.
Esempio n. 6
0
 public function __construct($transport)
 {
     parent::__construct(new TBinaryProtocolAccelerated($transport));
 }