fyiyy/swoole-rpc
最新稳定版本:v1.0
Composer 安装命令:
composer require fyiyy/swoole-rpc
包简介
README 文档
README
composer require fyiyy/swoole-rpc
使用
服务端使用
use Fy\Rpc\RpcServer;
class test
{
public function index($param)
{
return $param;
}
}
class server
{
public function index($param)
{
return $param;
}
public function test()
{
include_once 'vendor/autoload.php';
$config = [
'host' => '0.0.0.0',
'port' => 9502
];
$RpcServer = new RpcServer($config);
$RpcServer->add($this, 'index');
$RpcServer->add(new test(), 'index');
$RpcServer->addBatch(
['obj' => $this, 'method' => 'sayHello'],
['obj' => $this, 'method' => 'sayHello1']
);
$RpcServer->start();
}
/**
* @param string $name
* @return string
*/
public function sayHello(string $name): string
{
return 'Server Say ' . $name;
}
public function sayHello1(string $name): string
{
return 'Server Say11 ' . $name;
}
}
$obj = new server();
$obj->test();
客户端使用
use Fy\Rpc\RpcClient;
class client
{
public function test()
{
include_once 'vendor/autoload.php';
$config = [
'host' => '192.168.0.5',
'port' => 9502,
'timeOut' => 5
];
$client = new RpcClient($config);
$result = $client->setClass('server')->index(['code' => 1, 'msg' => 'server']);
var_dump($result);
$result = $client->setClass('server')->sayHello('Swoole');
var_dump($result);
$result = $client->setClass('test')->index(['code' => 1, 'msg' => 'test']);
var_dump($result);
$result = $client->setClass('server')->index(['code' => 1, 'msg' => 'server']);
var_dump($result);
$result = $client->setClass('server')->sayHello1('111111');
var_dump($result);
}
}
$obj = new client();
$obj->test();
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-02