Skip to content

bigplum/tfs-php-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Client for TFS(Taobao File System) without rcserver supporting

The original php-tfs-client need rcserver/meta_server, but they are diffcult to setup for less of documents. And also we don't need the features provided by rcserver.

So I wrote the new php client by wraping the c++ API:TfsClient.

Install

  1. tbsys/tbnet must be prepared

  2. copy *.cpp and *.h to tfs/src/phpclient

  3. copy tfs/src/common to tfs/src/phpclient/common

  4. modify the phpize and php-config path in the tfs/src/phpclient/build.sh

  5. run build.sh and make

  6. if error, create libtairclientapi.a and make again

    cd .libs; ar -r php_tfs_client.a php_tfs_client.o; cp -a ./php_tfs_client.a /lib/libtairclientapi.a;

  7. copy modules/tfs_client.so to php lib directory and modify php.ini to add the module

  8. excute run.sh to test the client

or download the precompiled tfs_client.so from modules directory directly.

Usage

There are only 4 functions now....

/**
*typedef enum
*{
*  T_DEFAULT = 0,
*  T_READ = 1,
*  T_WRITE = 2,
*  T_CREATE = 4,
*  T_NEWBLK = 8,
*  T_NOLEASE = 16,
*  T_STAT = 32,
*  T_LARGE = 64,
*  T_UNLINK = 128,
*  T_FORCE = 256
*} OpenFlag;
*/

$tfsobj = new tfs_client("localhost:8108", "INFO"); //log level: DEBUG/INFO/ERROR
echo "\n-------------------\n";
$data='XXXXXXXXXXXX';
$data_len = strlen($data);
echo "\n------------write data case------------\n";
$fd=$tfsobj->open(NULL,"",2);
echo "\n=============fd:$fd\n";
$ret=$tfsobj->write($fd, $data, $data_len);
echo "\n=============write ret:$ret\n";
$filename=$tfsobj->close($fd);
echo "\n=============close ret:$filename[0], $filename[1]\n";

echo "\n------------read data case------------\n";
$fd=$tfsobj->open($filename[1], "",1);

echo "\n------------stat file case------------\n";
$stat = $tfsobj->stat($fd);
var_dump($stat);
/*
array stat(
    int size;
    int modify_time;
    int create_time;
    int crc;
)
*/

echo "\n------------read data case------------\n";
$ary=$tfsobj->read($fd, 20);
echo "\n=============read data: length: $ary[0], data: $ary[1]\n";

$ret = $tfsobj->unlink($filename[1], "");
echo "\n=============unlink: $ret\n";

$st=$tfsobj->stat($fd);
echo "\nunlink stat: $st[0], $st[1], $st[2], $st[3]\n";

$tfsobj->close($fd);

About

A php client for TaoBao distributed filesystem without rcserver support.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published