Php / Thrift错误 - 寻找Php + hBase + Thrift工作示例

时间:2014-01-09 14:57:27

标签: php hbase thrift

我正在尝试使用PHP连接到我的hbase,虽然它在ROR中工作但我无法在PHP中使用它。我收到一个错误:

  

第8行的/home/gregoire/www/thrift.php中找不到“Thrift \ Transport \ TSocket”类

我可以用你想要的任何方式改变这条线我仍然会遇到这个错误,我对此感到困惑。有没有人有hbase / thrift / php机制的工作样本?我错过了什么,作为PHP的初学者。

<?php
    use Thrift\Transport\TSocket;
    use Thrift\Transport\TBufferedTransport;
    use Thrift\Protocol\TBinaryProtocolAccelerated;

    try {
        $socket = new Thrift\Transport\TSocket('10.10.9.41', 9090);
        $transport = new TBufferedTransport($socket, 1024, 1024);
        $protocol = new TBinaryProtocolAccelerated($transport);
        $client = new HbaseClient($protocol);
        $transport -> open();

        //show all tables
        $tables = $client -> getTableNames();
        foreach ($tables as $name) {
            echo("  found: {$name}\n");
        }
    } catch (Exception $e) {
        print_r($e);
    }
?>

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

<?php

$GLOBALS['THRIFT_ROOT'] = '/var/www/aa/thrift-lib/src';

require_once( $GLOBALS['THRIFT_ROOT'].'/Thrift.php' );
require_once( $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php' );
require_once( $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php' );
require_once( $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php' );
require_once( $GLOBALS['THRIFT_ROOT'].'/packages/Hbase/Hbase.php' );

$socket = new TSocket( 'master', 9090 );
$socket->setSendTimeout( 20000 ); 
$socket->setRecvTimeout( 40000 ); 
$transport = new TBufferedTransport( $socket );
$protocol = new TBinaryProtocol( $transport );
$client = new HbaseClient( $protocol );


$transport->open();


//show all tables
$tables = $client->getTableNames();
foreach ( $tables as $name ) {
echo( "  found: {$name}\n" );
}
$transport->close();
?>

$socket = new TSocket( 'master', 9090 );上的主要均值是mylocalhost,然后不要忘记生成hbase thrif php,在此代码中我必须将文件生成复制到我的webserver文件夹$GLOBALS['THRIFT_ROOT'] = '/var/www/aa/thrift-lib/src';