惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
V
V2EX
博客园 - 【当耐特】
V
Visual Studio Blog
宝玉的分享
宝玉的分享
D
DataBreaches.Net
Engineering at Meta
Engineering at Meta
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
News | PayPal Newsroom
Schneier on Security
Schneier on Security
I
InfoQ
博客园 - Franky
The GitHub Blog
The GitHub Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Commits to openclaw:main
Recent Commits to openclaw:main
AI
AI
WordPress大学
WordPress大学
Webroot Blog
Webroot Blog
L
LangChain Blog
Help Net Security
Help Net Security
V2EX - 技术
V2EX - 技术
TaoSecurity Blog
TaoSecurity Blog
O
OpenAI News
月光博客
月光博客
H
Hacker News: Front Page
F
Full Disclosure
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security Affairs
博客园 - 司徒正美
MyScale Blog
MyScale Blog
Vercel News
Vercel News
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Y
Y Combinator Blog
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hacker News: Ask HN
Hacker News: Ask HN
N
News and Events Feed by Topic
J
Java Code Geeks
Simon Willison's Weblog
Simon Willison's Weblog
Recent Announcements
Recent Announcements
D
Darknet – Hacking Tools, Hacker News & Cyber Security
I
Intezer
The Last Watchdog
The Last Watchdog
博客园_首页
C
Check Point Blog
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - pcwanli

Python批量将Word文档(.doc)转换为.docx格式的完整实现步骤 Linux下版本控制器(SVN) -命令行客户端 linux svn 命令 Qwen3-VL视频科技:内容审核系统搭建 svn update 出现Skipped 'feifazuzhi' -- Node remains in conflict处理方法 linux redis.service如何编写 深入php redis pconnect PHP中使用Redis长连接笔记 python happybase 批量读取 如何用phpredis持久化连接pconnect方法提升应用响应速度 python处理常见格式压缩包文件的全指南 Python编程:happybase读写HBase数据库 python redis zset 按分值获取记录 hbase日志如何清理 hbase日志清理 Python的time.strftime()方法 python re.sub第二参数,前值如何引用 【Python】基于python实现Windows Service程序 python解析url参数 提取网页源码头信息的正则表达式 PHP字符串分割:explode()函数详解与应用 python requests get请求禁用自动解压 python importlib动态模块加载遇到is not a package错误,解决方法。 Python正则表达式替换(re.sub)的6种典型应用场景 用Python处理HTML转义字符的5种方式 pymongo批量更新bulk_write php mongodb操作 使用thrift的php版本操作hbase数据库 PHP通过Thrift操作Hbase
PHP 通过 Thrift 操作 Hbase
pcwanli · 2026-03-04 · via 博客园 - pcwanli

来源:https://cloud.tencent.cn/developer/article/1981646

HBase是一个开源的NoSQL产品,它是实现了Google BigTable论文的一个开源产品,和Hadoop和HDFS一起,可用来存储和处理海量column family的数据。官方网址是:http://hbase.apache.org

一 、HBase访问接口

1. Native Java API,最常规和高效的访问方式,适合Hadoop MapReduce Job并行批处理HBase表数据 2. HBase Shell,HBase的命令行工具,最简单的接口,适合HBase管理使用 3. Thrift Gateway,利用Thrift序列化技术,支持C++,PHP,Python等多种语言,适合其他异构系统在线访问HBase表数据 4. REST Gateway,支持REST 风格的Http API访问HBase, 解除了语言限制 5. Pig,可以使用Pig Latin流式编程语言来操作HBase中的数据,和Hive类似,本质最终也是编译成MapReduce Job来处理HBase表数据,适合做数据统计 6. Hive,当前Hive的Release版本尚没有加入对HBase的支持,但在下一个版本Hive 0.7.0中将会支持HBase,可以使用类似SQL语言来访问HBase 如果使用PHP操作Hbase,推荐使用Facebook开源出来的thrift,官网是:http://thrift.apache.org/ ,它是一个类似ice的中间件,用于不同系统语言间信息交换。

二、安装Thrift

在Hadoop和Hbase都已经安装好的集群上安装Thrift,Thrift安装在Hmaster机器上

1. 下载thrift

wget http://mirror.bjtu.edu.cn/apache//thrift/0.8.0/thrift-0.8.0.tar.gz

2. 解压

tar -xzf thrift-0.8.0.tar.gz

3 .编译安装:

如果是源码编译的,首先要使用./boostrap.sh创建文件./configure ,我们这下载的tar包,自带有configure文件了。((可以查阅README文件))

If you are building from the first time out of the source repository, you will need to generate the configure scripts. (This is not necessary if you downloaded a tarball.) From the top directory, do: ./bootstrap.sh

./configure make ; make install

4. 启动:

# ./bin/hbase-daemon.sh start thrift [--port=PORT] starting thrift, logging to /home/banping/hbase/hbase-0.90.3/bin/../logs/hbase-root-thrift-localhost.localdomain.out

Thrift默认监听的端口是9090

使用jps查看进程,看到ThriftServer进程:

三、测试:

1 .php脚本库操作Hbase

PHP通过Thrift访问Hbase的库是在thrift-0.8.0/lib/php/src目录下,其实这个文件夹下也包含通过Thrift访问Hbase的PHP扩展源代码。

1)复制thrift-0.8.0/lib/php到相应的php web目录。

2)然后生成php与hbase接口文件

#/usr/local/thrift/bin/thrift --gen php /usr/local/hbase/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift

#(根据自己的目录设置)

生成目录文件: /usr/local/hbase/gen-php/Hbase

有文件: Hbase.php,Hbase_types.php

把Hbase.php,Hbase_types.php copy到:web目录/php/src/packages/Hbase/

3)使用php脚本测试:

<?php

ini_set('display_errors', E_ALL);
$GLOBALS['THRIFT_ROOT'] = './php/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('10.64.60.83', '9090');

$socket->setSendTimeout(10000); 

通过浏览器查看看到项目中的所有表,证明PHP可以通过thrift访问HBase了。

2. 使用PHP扩展的方式来使用thrift

我们使用PHP自带的phpize来生成Thtift的php扩展。该扩展的源码结构:

hadoop@ubuntu:/usr/local/hbase-0.90.4/thrift-0.8.0/lib/php/src cdext/thriftprotocol /usr/local/php/bin/phpize ./configurewithphpconfig=/usr/local/php/bin/phpconfigenablethriftprotocol make

然后把生成的thrift_protocol.so文件配置到php.ini并重启apache服务。