php httpfs链接hdfs

一.代码(有bug)

GitHub - michaelbutler/php-WebHDFS: A PHP client for WebHDFS

二.调用代码

1.代码1.代码

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| require_once('../webhdfs/src/org/apache/hadoop/WebHDFS.php');require_once('../webhdfs/src/org/apache/hadoop/tools/Curl.php'); require_once('../webhdfs/src/org/apache/hadoop/WebHDFS/Exception.php'); $host = '192.168.168.126'; $hdfs = new org\apache\hadoop\WebHDFS( $host, '14000', 'hdfs', 'Master00', '9000', false); echo $hdfs->getHomeDirectory(); //echo "<br>";查看目录状态$response = $hdfs->listDirectories('/user/hdfs/');//上传$response = $hdfs->create('/user/hdfs/ls/composer.json','./webfs.txt'); //默认覆盖查看文件内容$response = $hdfs->open('/user/hdfs/ls/composer.json');echo "<br>";var_dump($response); |

GitHub - michaelbutler/php-WebHDFS: A PHP client for WebHDFS

|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| <?php //luozhen@antiy.cn require_once('../webhdfs/src/org/apache/hadoop/WebHDFS.php'); require_once('../webhdfs/src/org/apache/hadoop/tools/Curl.php'); require_once('../webhdfs/src/org/apache/hadoop/WebHDFS/Exception.php'); $host = '192.168.168.126'; $hdfs = new org\apache\hadoop\WebHDFS( $host, '14000', 'hdfs', 'Master00', '9000', false); echo $hdfs->getHomeDirectory(); ``查看目录状态 $response = $hdfs->listDirectories('/user/hdfs/'); //上传 $response = $hdfs->create('/user/hdfs/ls/composer.json','./webfs.txt'); //默认覆盖 查看文件内容 $response = $hdfs->open('/user/hdfs/ls/composer.json'); echo "<br>";var_dump($response); |

GitHub - michaelbutler/php-WebHDFS: A PHP client for WebHDFS

四.代码有bug。当上传文件时,这个代码有bug

解决方式,加头即可。

四.调用说明,来自README.md

文件和目录操作

创建和写入文件
复制代码
hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ hdfs - > create(' user / hadoop-username / new-file.txt ',' local-file.txt ');
直接创建内容并将其写入文件
复制代码
hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ hdfs - > createWithData(' user / hadoop-username / new-file.txt ',' content ');
附加到文件
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ hdfs - > append(' user / hadoop-username / file-to-append-to.txt ',' local-file.txt ');
Concat文件
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ hdfs - > concat(' user / hadoop-username / concatenated-file.txt ',' / test / file1,/ test / file2,/ test / file3 ');
打开并读取文件
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ response  =  $ hdfs - > open(' user / hadoop-username / file.txt ');
制作目录
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ hdfs - > mkdirs(' user / hadoop-username / new / directory / structure ');
创建符号链接
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ hdfs - > createSymLink(' user / hadoop-username / file.txt ',' / user / hadoop-username / symlink - to -file.txt ');
重命名文件/目录
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ hdfs - > rename(' user / hadoop-username / file.txt ',' / user / hadoop-username / renamed -file.txt ');
删除文件/目录
复制代码
hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ hdfs - > delete(' user / hadoop-username / file.txt ');
文件/目录的状态
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ response  =  $ hdfs - > getFileStatus(' user / hadoop-username / file.txt ');
列出目录
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ response  =  $ hdfs - > listStatus(' user / hadoop-username / ');

其他文件系统操作

获取目录的内容摘要
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ response  =  $ hdfs - > getContentSummary(' user / hadoop-username / ');
获取文件校验和
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ response  =  $ hdfs - > getFileChecksum(' user / hadoop-username / file.txt ');
获取主目录
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ response  =  $ hdfs - > getHomeDirectory();
设置权限
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ hdfs - > setPermission(' user / hadoop-username / file.txt ',' 777 ');
设置所有者
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ hdfs - > setOwner(' user / hadoop-username / file.txt ',' other-user ');
设置复制因子
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ hdfs - > setReplication(' user / hadoop-username / file.txt ',' 2 ');
设置访问或修改时间
复制代码
$ hdfs  =  new  WebHDFS(' mynamenode.hadoop.com ',' 50070 ',' hadoop-username '); 
$ response  =  $ hdfs - > setTimes(' user / hadoop-username / file.txt ');
相关推荐
cr.sheeper6 分钟前
CTFHUB-web进阶-php
开发语言·php
Clockwiseee30 分钟前
PHP之伪协议
android·开发语言·php
开心工作室_kaic41 分钟前
springboot498基于javaweb的宠物猫认养系统(论文+源码)_kaic
java·开发语言·数据库·美食
跨境商城搭建开发1 小时前
一个服务器可以搭建几个网站?搭建一个网站的流程介绍
运维·服务器·前端·vue.js·mysql·npm·php
秋雨凉人心1 小时前
上传npm包加强
开发语言·前端·javascript·webpack·npm·node.js
凡人的AI工具箱1 小时前
每天40分玩转Django:Django文件上传
开发语言·数据库·后端·python·django
cloud___fly1 小时前
Java线程池面试题
java·开发语言
hackeroink1 小时前
【网络安全零基础入门】PHP环境搭建、安装Apache、安装与配置MySQL(非常详细)零基础入门到精通,收藏这一篇就够(01)_php安装配置教程
web安全·php·apache
小白学大数据2 小时前
Python爬虫:爱奇艺榜单数据的实时监控
开发语言·爬虫·python