knik / gameap-daemon-client
GameAP Daemon PHP 客户端
0.6.6
2023-05-04 16:09 UTC
Requires
- php: >=7.2
- ext-openssl: *
- ext-sockets: *
- knik/binn: ^0.9 || ^1
Requires (Dev)
- mockery/mockery: ^1.3.4
- phpunit/phpunit: ^8.5.14 || ^9.0
README
安装
composer require knik/gameap-daemon-client
使用方法
命令
连接到服务器
$gdaemonCommands = new GdaemonCommands([ 'host' => 'localhost', 'port' => 31717, 'serverCertificate' => '/path/to/server.crt', 'localCertificate' => '/path/to/client.crt', 'privateKey' => '/path/to/client.key.pem', 'privateKeyPass' => '1234', 'timeout' => 10, 'workDir' => '/home/user', ]); $gdaemonCommands->connect();
执行命令
$result = $gdaemonCommands->exec('echo HELLO'); var_dump($result); // string(5) "HELLO"
退出代码
$result = $gdaemonCommands->exec('echo HELLO', $exitCode); var_dump($result); // string(5) "HELLO" var_dump($exitCode); // int(0)
文件
连接到服务器
$gdaemonFiles = new GdaemonFiles([ 'host' => 'localhost', 'port' => 31717, 'serverCertificate' => '/path/to/server.crt', 'localCertificate' => '/path/to/client.crt', 'privateKey' => '/path/to/client.key.pem', 'privateKeyPass' => '1234', 'timeout' => 10, ]); $gdaemonFiles->connect();
列出目录
关于文件的详细信息
$result = $gdaemonFiles->directoryContents('/path/to/dir'); print_r($result); /* Array ( [0] => Array ( [name] => directory [size] => 0 [mtime] => 1542013640 [type] => dir [permissions] => 0755 ) [1] => Array ( [name] => file.txt [size] => 15654 [mtime] => 1542013150 [type] => file [permissions] => 0644 ) ) */
仅文件名
$result = $gdaemonFiles->listFiles('/path/to/dir'); print_r($result); Array ( [0] => directory [1] => file.txt )
创建目录
$gdaemonFiles->mkdir('/path/to/new_dir');
删除
$gdaemonFiles->delete('/path/to/file.txt');
删除包含其他文件或目录的目录
$gdaemonFiles->delete('/path/to/file.txt', true);
重命名
重命名或移动文件/目录
$gdaemonFiles->rename('/path/to/file.txt', '/path/to/new_name.txt');
复制
$gdaemonFiles->copy('/path/to/file.txt', '/path/to/new_file.txt');
更改权限
$gdaemonFiles->chmod(0755, '/path/to/file.txt');
存在检查
$gdaemonFiles->exist('/path/to/file.txt');
元数据
$result = $gdaemonFiles->directoryContents('/path/to/file.txt'); print_r($result); /* Array ( [name] => file.txt [size] => 43 [type] => file [mtime] => 1541971363 [atime] => 1541971363 [ctime] => 1541971363 [permissions] => 0644 [mimetype] => text/plain ) */
从服务器下载文件
$gdaemonFiles->get('/remote/path/to/file.txt', '/local/path/to/file.txt');
文件句柄
$fileHandle = fopen('php://temp', 'w+b'); $gdaemonFiles->get('/remote/path/to/file.txt', $fileHandle);
上传文件
$gdaemonFiles->put('/local/path/to/file.txt', '/remote/path/to/file.txt');
文件句柄
$fileHandle = fopen('/local/path/to/file.txt', 'r'); $gdaemonFiles->put($fileHandle, '/remote/path/to/file.txt');
状态
连接到服务器
$gdaemonStatus = new GdaemonStatus([ 'host' => 'localhost', 'port' => 31717, 'serverCertificate' => '/path/to/server.crt', 'localCertificate' => '/path/to/client.crt', 'privateKey' => '/path/to/client.key.pem', 'privateKeyPass' => '1234', 'timeout' => 10, ]); $gdaemonStatus->connect();
GameAP Daemon 版本
获取 GameAP Daemon 版本和编译日期
$version = $gdaemonStatus->version();
基本信息
获取运行时间信息,工作等待任务数量,在线服务器列表数量
$info = $gdaemonStatus->infoBase();
详细信息
获取运行时间信息,工作等待任务 ID 列表,在线服务器列表 ID 列表
$info = $gdaemonStatus->infoDetails();