php phdfs扩展,hadoop HDFS的PHP扩展—PHDFS

现在的业务使用hadoop hdfs来存储咨询日志,最早用了2个方案

1) 直接java,通过PHP调用java来使用

2) php 通过thrift 来调用

都感觉不是很顺畅。

后来开发phdfs 直接用php扩展的方式来简单的操作hdfs

代码地址:http://pecl.php.net/package/phdfs

Requirements

PHP Version: PHP 5.3+

ZTS Enabled ( Thread Safety )

Installing Hadoop

class phdfs {

/* variable */

public $host= "127.0.0.1" ;//hadoop ip

public $port = "9000";//hadoop port /

public function __construct(string $host,string $port);

/***

* Connect to a hdfs file system. Connect to the hdfs.

* Returns true on success, false on error.

*/

public function connect();

/***

* Disconnect from the hdfs file system. Disconnect from hdfs.

* Returns true on success, false on error.

*/

public function disconnect();

/***

* Checks if a given path exsits on the filesystem

* Returns true on success, false on error.

*/

public function exists(string $path);

/***

* Write data into an open file.

* int mode: O_WRONLY 、O_CREAT、O_APPEND

* Returns true on success, false on error.

*/

public function write(string $file,string buffer [, int $mode ]);

/***

* Read data from an open file.

* $buffer_len default 1024k

* Returns true on success, false on error.

*/

public function read(string $file[,int $buffer_len]);

/***

* Get information about a path

* Returns array on success, false on error.

*/

public function file_info(string $path);

/***

* make the given file and all non-existent parents into directories.

* Returns true on success, false on error.

*/

public function create_directory(string $path);

/***

* Rename file.

* Returns true on success, false on error.

*/

public function rename(sting $old_path,sting $new_ptah);

/***

* Get list of files/directories for a given directory-path

* Returns true on success, false on error.

*/

public function list_directory(string $path);

/***

* Get the current offset in the file, in bytes.

* Returns Current offset, false on error.

*/

public function tell(string $file [, int $buffer_len ]);

/***

* Copy file

* Returns true on success, false on error.

*/

public function copy(string $source_file,string $destination_file);

/***

* Delete file

* Returns true on success, false on error.

*/

public function delete($string $file);

}

try {

$obj = new phdfs();

$obj->port = "9000";

$obj->ip = "127.0.0.1";

$obj->connect();

//create file

$log = $obj->write("/a/b/c/test1.txt","test",O_WRONLY|O_CREAT);

//appden file

$log = $obj->write("/a/b/c/test2.txt","test",O_WRONLY|O_APPEND);

var_dump($log);

echo $obj->rename("/a/b/c/test2.txt","/a/b/c/test3.txt");

}catch (Exception $ex) {

echo $ex->getMessage();

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值