PHP实现的FastDFS客户端
composer require rayson-x/fast-dfs
参考java版实现
单元测试使用的服务端版本为FastDFS_V6.07
PHP版本要求8.0以上
use Ant\FastDFS\TrackerClient;
include __DIR__ . "/vendor/autoload.php";
// 初始化追踪服务器客户端
$trackerClient = new TrackerClient(['localhost:22122']);
// 随机获取存储服务客户端
$storageClient = $trackerClient->getStorageClient();
// 根据组名获取
$storageClient = $trackerClient->getStorageClientWithGroup('group1');
// 获取根据断点续传的文件获取可用的存储服务
$storageClient = $trackerClient->getAppendClient('group1', 'M00/00/5B/wKgM_mFMPeWEEzrOAAAAALdUwZ4945.txt');
// 根据文件路径上传
$storePath = $storageClient->uploadFile('filepath');
// 上传字符串
$storePath = $storageClient->uploadBuffer('foobar', 'txt');
// group1/M00/00/52/wKgM_mFFkIiIX2FYAAAAPDbjiZ4AAAAcQCptLQAAABU459.txt
$urlPath = "{$storePath->group}/{$storePath->path}";
// 根据文件路径上传
$storePath = $storageClient->uploadFile('filepath', true);
// 上传字符串
$storePath = $storageClient->uploadBuffer('foobar', 'txt', true);
// 追加一个文件
$storageClient->appendFile($storePath->path, 'filepath');
// 追加字符串
$storageClient->appendFile($storePath->path, 'foobar');
- 分部署部署时,多台tracker服务器处理
- 实现一个可自定义的连接器
- 支持ReactPhp,Swoole,默认Socket
- 常驻进程模式支持连接池