编译Hbase-thrift-php客户端
来源:互联网 发布:梦三国单机版完整数据 编辑:程序博客网 时间:2024/06/08 05:10
问题
hbase没有提供PHP客户端来访问hbase,只能通过thrift的方式来连接hbase,但是坑爹的是这个方法也得自己去编译,环境的准备也是很繁琐的,记录下
环境搭建
主要是安装thrift,但是thrift依赖很多其他库,所以你要花费一段时间去搞定环境安装,以官方安装教程为准
OS X Setup
安装完成后,确保thrift
命令是可用的。
编译php-thrift-hbase
hbase.thrift
生成Hbase.php
和Types.php
两个文件
hbase.thrift2
生成THBaseService.php
和Types.php
两个文件
我打包上传这些文件php-hbase-thrift
代码文件添加到项目中
Thrift-php移到到项目中
如果选择thrift,把上一步产生的2个hbase文件放到相同目录下
测试程序
<?php/***Thrift Test Class by xinqiyang*/ini_set('display_error', E_ALL);$GLOBALS['THRIFT_ROOT'] = './lib';/* Dependencies. In the proper order. */require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Transport/TTransport.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Transport/TSocket.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Protocol/TProtocol.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Protocol/TBinaryProtocol.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Transport/TBufferedTransport.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Type/TMessageType.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Factory/TStringFuncFactory.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/StringFunc/TStringFunc.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/StringFunc/Core.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Type/TType.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Exception/TException.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Exception/TTransportException.php';require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/Exception/TProtocolException.php';/* Remember these two files? */require_once $GLOBALS['THRIFT_ROOT'].'/Types.php';require_once $GLOBALS['THRIFT_ROOT'].'/Hbase.php';use Thrift\Protocol\TBinaryProtocol;use Thrift\Transport\TSocket;use Thrift\Transport\TSocketPool;use Thrift\Transport\TFramedTransport;use Thrift\Transport\TBufferedTransport;use Hbase\HbaseClient;//define host and port$host = '192.168.56.56';$port = 9090;$socket = new Thrift\Transport\TSocket($host, $port);$transport = new TBufferedTransport($socket);$protocol = new TBinaryProtocol($transport);// Create a calculator client$client = new HbaseClient($protocol);$transport->open();//echo "Time: " . $client -> time();$tables = $client->getTableNames();sort($tables);foreach ($tables as $name) { echo $name."\r\n";}//create a fc and then create a table$columns = array( new \Hbase\ColumnDescriptor(array( 'name' => 'id:', 'maxVersions' => 10 )), new \Hbase\ColumnDescriptor(array( 'name' => 'name:' )), new \Hbase\ColumnDescriptor(array( 'name' => 'score:' )),);$tableName = "student";/*try { $client->createTable($tableName, $columns);} catch (AlreadyExists $ae) { var_dump( "WARN: {$ae->message}\n" );}*/// get table descriptors$descriptors = $client->getColumnDescriptors($tableName);asort($descriptors);foreach ($descriptors as $col) { var_dump( " column: {$col->name}, maxVer: {$col->maxVersions}\n" );}//set clomn//add update column data$time = time();var_dump($time);$row = '2';$valid = "foobar-".$time;$mutations = array( new \Hbase\Mutation(array( 'column' => 'score', 'value' => $valid )),);$mutations1 = array( new \Hbase\Mutation(array( 'column' => 'score:a', 'value' => $time, )),);$attributes = array ();//add row, write a row$row1 = $time;$client->mutateRow($tableName, $row1, $mutations1, $attributes);echo "-------write row $row1 ---\r\n";//update row$client->mutateRow($tableName, $row, $mutations, $attributes);//get column data$row_name = $time;$fam_col_name = 'score:a';$arr = $client->get($tableName, $row_name, $fam_col_name, $attributes);// $arr = arrayforeach ($arr as $k => $v) { // $k = TCell echo " ------ get one : value = {$v->value} , <br> "; echo " ------ get one : timestamp = {$v->timestamp} <br>";}echo "----------\r\n";$arr = $client->getRow($tableName, $row_name, $attributes);// $client->getRow return a arrayforeach ($arr as $k => $TRowResult) { // $k = 0 ; non-use // $TRowResult = TRowResult var_dump($TRowResult);}echo "----------\r\n";/****** //no test public function scannerOpenWithScan($tableName, \Hbase\TScan $scan, $attributes); public function scannerOpen($tableName, $startRow, $columns, $attributes); public function scannerOpenWithStop($tableName, $startRow, $stopRow, $columns, $attributes); public function scannerOpenWithPrefix($tableName, $startAndPrefix, $columns, $attributes); public function scannerOpenTs($tableName, $startRow, $columns, $timestamp, $attributes); public function scannerOpenWithStopTs($tableName, $startRow, $stopRow, $columns, $timestamp, $attributes); public function scannerGet($id); public function scannerGetList($id, $nbRows); public function scannerClose($id);*/echo "----scanner get ------\r\n";$startRow = '1';$columns = array ('column' => 'score', );//$scan = $client->scannerOpen($tableName, $startRow, $columns, $attributes);//$startAndPrefix = '13686667';//$scan = $client->scannerOpenWithPrefix($tableName,$startAndPrefix,$columns,$attributes);//$startRow = '1';//$stopRow = '2';//$scan = $client->scannerOpenWithStop($tableName, $startRow, $stopRow, $columns, $attributes);//$arr = $client->scannerGet($scan);$nbRows = 1000;$arr = $client->scannerGetList($scan, $nbRows);var_dump('count of result :'.count($arr));foreach ($arr as $k => $TRowResult) { // code... //var_dump($TRowResult);}$client->scannerClose($scan);//close transport$transport->close();
0 0
- 编译Hbase-thrift-php客户端
- php thrift for HBase
- thrift php客户端编写
- thrift php客户端编写
- PHP通过Thrift操作Hbase
- PHP通过Thrift操作Hbase
- php通过thrift操作hbase
- PHP通过Thrift操作Hbase
- PHP操作HBASE(通过thrift)
- 搭建HBase+thrift+php环境
- php通过thrift操作hbase
- php通过thrift操作hbase
- PHP通过Thrift操作Hbase
- 搭建HBase+thrift+php环境
- 通过thrift使用PHP访问Hbase
- php通过thrift 0.9.0操作HBase
- HBase Thrift
- thrift的安装以及php客户端编写
- codeforces比赛记录
- Android创建自定义系统键盘
- throw 与throws
- 量化分析师的Python日记【Q Quant兵器谱之函数插值】
- Oracle_sql_(4)
- 编译Hbase-thrift-php客户端
- 最简单的隐藏文件夹方法
- anaconda 使用import sklearn.model_selection 出错ImportError: No module named model_selection
- Python 中的进程、线程、协程、同步、异步、回调
- Android 自定义View画天气预报折线图
- iframe脚本木马攻防浅析
- SDK开发心得
- Cookie/Session机制详解
- 为什么要有maven