|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
PHP成功的插入,删除,更新数据的时候,显然,你已经距离成功指日可待了。
php可以经由过程thrift毗连hbase,一样php可以经由过程thrift读取hadoop资本(hdfs资本)。
筹办:
php需求thrift的libary
packages:hadoop-0.20.2\src\contrib\thriftfs\gen-php
源码:
<?php
$globals['thrift_root'] = rootpath . '/lib/thrift';
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/hadoopfs/thrifthadoopfilesystem.php");
$hadoop_socket = new tsocket("localhost", 59256);
$hadoop_socket -> setsendtimeout(10000); // ten seconds
$hadoop_socket -> setrecvtimeout(20000); // twenty seconds
$hadoop_transport = new tbufferedtransport($hadoop_socket);
$hadoop_protocol = new tbinaryprotocol($hadoop_transport);
$hadoopclient = new thrifthadoopfilesystemclient($hadoop_protocol);
$hadoop_transport -> open();
try {
// create directory
$dirpathname = new hadoopfs_pathname(array("pathname" => "/user/root/hadoop"));
if($hadoopclient -> exists($dirpathname) == true) {
echo $dirpathname -> pathname . " exists.\n";
} else {
$result = $hadoopclient -> mkdirs($dirpathname);
}
// put file
$filepathname = new hadoopfs_pathname(array("pathname" => $dirpathname -> pathname . "/hello.txt"));
$localfile = fopen("hello.txt", "rb");
$hdfsfile = $hadoopclient -> create($filepathname);
while(true) {
$data = fread($localfile, 1024);
if(strlen($data) == 0)
break;
$hadoopclient -> write($hdfsfile, $data);
}
$hadoopclient -> close($hdfsfile);
fclose($localfile);
// get file
echo "read file:\n";
print_r($filepathname);
$data = "";
$hdfsfile = $hadoopclient -> open($filepathname);
print_r($hdfsfile);
while(true) {
$data = $hadoopclient -> read($hdfsfile, 0, 1024);
if(strlen($data) == 0)
break;
print $data;
}
$hadoopclient -> close($hdfsfile);
echo "liststatus:\n";
$result = $hadoopclient -> liststatus($dirpathname);
print_r($result);
foreach($result as $key => $value) {
if($value -> isdir == "1")
print "dir\t";
else
print "file\t";
print $value -> block_replication . "\t" . $value -> length . "\t" . $value -> modification_time . "\t" . $value -> permission . "\t" . $value -> owner . "\t" . $value -> group . "\t" . $value -> path . "\n";
}
$hadoop_transport -> close();
} catch(exception $e) {
print_r($e);
}
?>
启动hadoop的thrift
hadoop-0.20.2\src\contrib\thriftfs\scripts\start_thrift_server.sh 59256
problem one:
在体系目次创立文件,而不是在hadoop目次中创立文件
缘由:
thrift启动时加载默许的设置装备摆设文件
处理办法:
修正start_thrift_server.sh文件
top=/usr/local/hadoop-0.20.2
classpath=$classpath:$top/conf
problem two:
java.lang.nullpointerexception
at org.apache.hadoop.thriftfs.hadoopthriftserver$hadoopthrifthandler.write(hadoopthriftserver.java:282)
at org.apache.hadoop.thriftfs.api.thrifthadoopfilesystem$processor$write.process(unknown source)
at org.apache.hadoop.thriftfs.api.thrifthadoopfilesystem$processor.process(unknown source)
at com.facebook.thrift.server.tthreadpoolserver$workerprocess.run(unknown source)
at java.util.concurrent.threadpoolexecutor$worker.runtask(threadpoolexecutor.java:886)
at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:908)
at java.lang.thread.run(thread.java:662)
缘由:
java前往的map hash id为long类型,而php(32位)没法存储long类型的数据,招致转换成float数据后丧失精度。
private long nextid = new random().nextlong();
java前往数据:4207488029786584864 本文链接http://www.cxybl.com/html/wlbc/Php/20120607/28513.html学习数据库了,MYSQL可算是PHP的黄金搭档了,不过,虽然话是这么说,你也可能恨不得把MYSQL给生吞活剥了,因为这一行一列的东东简直让自己头晕目眩。 |
|