public static function add_node($host, $port = self::DEFAULT_THRIFT_PORT, $perist = true, $read_timeoutms = 300) { try { // Create Thrift transport and binary protocol cassandra client $sock = new TSocket($host, $port, $perist); $sock->setRecvTimeout(10000); $sock->setDebug('error_log'); $transport = new TBufferedTransport($sock, 10240, 10240); $client = new CassandraClient(new TBinaryProtocolAccelerated($transport)); // Store it in the connections self::$connections[] = array('transport' => $transport, 'client' => $client); // Done return TRUE; } catch (TException $tx) { self::$last_error = 'TException: ' . $tx->getMessage() . "\n"; } return FALSE; }
$GLOBALS['THRIFT_ROOT'] = !isset($GLOBALS['THRIFT_ROOT']) ? CODE_BASE2 . '/third_part/thrift-0.5.0' : $GLOBALS['THRIFT_ROOT']; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/packages/scribe/scribe.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/transport/THttpClient.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TFramedTransport.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TBufferedTransport.php'; //生成的文件 require_once dirname(__FILE__) . '/Hive.php'; //数据库文件 include_once '../DB/MyDB.class.php'; ERROR_REPORTING(E_ALL); INI_SET('DISPLAY_ERRORS', 'ON'); $socket = new TSocket('hive.corp.xx.com', 13080); $socket->setDebug(TRUE); // 设置接收超时(毫秒) $socket->setSendTimeout(10000); $socket->setRecvTimeout(30 * 60 * 1000); //接受时间设置为30分钟 //$transport = new TBufferedTransport($socket, 1024, 1024); $transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($transport); $client = new HiveClient($protocol); try { $transport->open(); } catch (TException $tx) { echo $tx->getMessage(); exit; } $yesterday = date("Y-m-d", strtotime("-1 day"));