简体   繁体   中英

Php / Thrift error - Looking for Php + hBase + Thrift working example

I am trying to connect to my hbase using PHP and while it worked in ROR I just can't make it work in PHP. I am getting an error:

Class 'Thrift\\Transport\\TSocket' not found in /home/gregoire/www/thrift.php on line 8

I can change the line in whatever way you'd like I still get this error, I am stuck at this. Does anyone have a working sample of hbase/thrift/php mechanism? What did I miss, as very beginner in 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);
    }
?>

Try the following:

<?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();
?>

master mean on $socket = new TSocket( 'master', 9090 ); is mylocalhost, then don't forget to generate hbase thrif php , in this code I have to copy file generate to my webserver folder $GLOBALS['THRIFT_ROOT'] = '/var/www/aa/thrift-lib/src';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM