程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP基礎知識 >> hadoop HDFS的PHP擴展—PHDFS

hadoop HDFS的PHP擴展—PHDFS

編輯:PHP基礎知識
 

現在的業務使用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);

}
<?php
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();
}
?>

 

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved