moee / bushtaxi
ZeroMQ 连接管理器,适用于 PHP (alpha)
0.0.1-alpha
2016-11-24 12:12 UTC
Requires
- php: >=7.0
- ext-zmq: *
Requires (Dev)
- bramus/monolog-colored-line-formatter: ~2.0
- monolog/monolog: ^1.21
- phpunit/phpunit: 5.6.*
- pimple/pimple: ^3.0
Suggests
- monolog/monolog: ^1.21
This package is not auto-updated.
Last update: 2024-09-23 12:49:12 UTC
README
Bushtaxi 致力于让您的 ZeroMQ 使用更简单。它基于简单的配置建立连接和绑定。
使用方法
客户端
req 套接字的配置示例如下
$config = [
"service" => [ "name" => "client" ],
"links" => [
"server" => [
"type" => "req",
"connect" => "tcp://10.0.0.100:5000"
]
]
];
使用此配置,您现在可以轻松地向配置中指定的套接字发送消息。
$bushtaxi = new Bushtaxi\Client($config);
$bushtaxi->server->send('Hello World');
服务器
绑定套接字和运行服务器同样简单。首先创建一个配置。
$config = [
"service" => [ "name" => "server" ],
"links" => [
"client" => [
"type" => "rep",
"bind" => "tcp://10.0.0.100:5000
]
]
];
除了配置外,您还需要指定一个 服务器运行时类。此运行时类决定了每个循环中会发生什么。
$runtime = new class extends Bushtaxi\AbstractServerRuntime {
function handle($links) {
$message = $links['client']->recv();
$links['client']->send("World");
}
};
然后我们就可以开始了
$bushtaxi = new Bushtaxi\Server($config, $runtime);
$bushtaxi->run();
您可以在 示例目录 中找到这个示例。
运行测试
cd bushtaxi
for f in $(find tests/*.yml); do docker-compose -f $f up; done