Example #1
0
define('HBASE_HOST', '192.168.0.106');
define('HBASE_PORT', 9090);
// load thrift lib for php
require_once THRIFT_ROOT . '/Thrift.php';
require_once THRIFT_ROOT . '/transport/TSocket.php';
require_once THRIFT_ROOT . '/transport/TBufferedTransport.php';
require_once THRIFT_ROOT . '/protocol/TBinaryProtocol.php';
// load the thrift generated stub
require_once dirname(__FILE__) . '/Hbase.php';
// open connection
$socket = new TSocket(HBASE_HOST, HBASE_PORT);
$transport = new TBufferedTransport($socket);
$protocol = new TBinaryProtocol($transport);
$transport->open();
// create hbase client
$client = new HbaseClient($protocol);
// show all tables
echo "Existing tables:\n";
$tables = $client->getTableNames();
foreach ($tables as $name) {
    echo "  found: {$name}\n";
}
// create a table with name 'tableName'
echo "\nCreate table: tableName\n";
try {
    $columns = array(new ColumnDescriptor(array('name' => 'colFamily:', 'maxVersions' => 10)));
    $client->createTable("tableName", $columns);
} catch (AlreadyExists $ae) {
    echo "WARN: {$ae->message}\n";
}
// insert data to table
Example #2
0
{
    echo "row: {$rowresult->row}, cols: \n";
    $values = $rowresult->columns;
    asort($values);
    foreach ($values as $k => $v) {
        echo "  {$k} => {$v->value}\n";
    }
}
$socket = new TSocket('localhost', 9090);
$socket->setSendTimeout(10000);
// Ten seconds (too long for production, but this is just a demo ;)
$socket->setRecvTimeout(20000);
// Twenty seconds
$transport = new TBufferedTransport($socket);
$protocol = new TBinaryProtocol($transport);
$client = new HbaseClient($protocol);
$transport->open();
$t = 'demo_table';
?>
<html>
<head>
<title>DemoClient</title>
</head>
<body>
<pre>
<?php 
#
# Scan all tables, look for the demo table and delete it.
#
echo "scanning tables...\n";
$tables = $client->getTableNames();
Example #3
0
						<?php 
ini_set('display_errors', E_ALL);
$GLOBAL['THRIFT_ROOT'] = 'C:\\wamp\\www\\Hbase\\Thrift';
include_once 'Thrift\\Thrift.php';
include_once 'Thrift\\TProtocolFactory.php';
include_once 'Thrift\\Hbase.php';
//访问Hbase,获取时间戳
$host = '192.168.100.2';
$port = 9090;
$socket = new TSocket($host, $port);
$socket->setSendTimeout(10000);
$socket->setRecvTimeout(20000);
$transport = new TBufferedTransport($socket);
$protocol = new TBinaryProtocol($transport);
$client = new HbaseClient($protocol);
$transport->open();
$table_name = 'facerecord';
$getId = $_GET['id'];
$row_name = "r" . $getId;
//$row_name = "r0";
$fam_col_name = array('count', 'info');
$arr = array();
$arr = $client->getRow($table_name, $row_name, $fam_col_name);
$transport->close();
$time_list = $arr[0]->columns;
$count_num = $time_list['count:num']->value;
//foreach($time_list as $mas);
for ($i = $count_num; $i > 0; $i--) {
    $index = "info:" . $i;
    $msg = $time_list[$index]->value;
Example #4
0
    } else {
        if ($ch_date[0] > 0) {
            $date = $ch_date[0] . "{$in_txt}" . $ch_date[1] . "{$in_txt}" . $ch_date[2];
        }
    }
    return $date;
}
$action = $_REQUEST['action'];
switch ($action) {
    case "getContext":
        $key = $_REQUEST['key'];
        //open connection
        $socket = new TSocket('localhost', 9090);
        $transport = new TBufferedTransport($socket);
        $protocol = new TBinaryProtocol($transport);
        $client = new HbaseClient($protocol);
        $transport->open();
        //show all tables
        $tables = $client->getTableNames();
        $context = $client->get('BigLaw', $key, "M:Context", array());
        $context = $context[0];
        $type = $client->get('BigLaw', $key, "M:Type", array());
        $case = $client->get('BigLaw', $key, "M:Case", array());
        $court = $client->get('BigLaw', $key, "M:Court", array());
        $date = $client->get('BigLaw', $key, "M:Date", array());
        $date = $date;
        if ($_REQUEST['type'] == "json") {
            $result = array("key" => $key, "court" => $court, "type" => $type, "case" => $case, "date" => $date, "context" => $context);
            print_r(json_encode($result));
        } else {
            print_r($context->value);