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.
-
tbsys/tbnet must be prepared
-
copy *.cpp and *.h to tfs/src/phpclient
-
copy tfs/src/common to tfs/src/phpclient/common
-
modify the phpize and php-config path in the tfs/src/phpclient/build.sh
-
run build.sh and make
-
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;
-
copy modules/tfs_client.so to php lib directory and modify php.ini to add the module
-
excute run.sh to test the client
or download the precompiled tfs_client.so from modules directory directly.
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);