concerto / comms
使用 Unix 域套接字进行进程间通信的库。
v0.8
2014-08-15 22:50 UTC
Requires
- php: >=5.4.0
- concerto/sockets: 0.*
- react/event-loop: 0.4.*
- react/socket: 0.4.*
This package is not auto-updated.
Last update: 2020-08-07 18:31:41 UTC
README
使用 Unix 域套接字进行进程间通信的库。
安装
安装 Comms 的推荐方法是 通过 composer。
{ "require": { "concerto/comms": "0.*" } }
使用方法
服务器
use Concerto\Comms\Server; use React\EventLoop\Factory; $loop = Factory::create(); $comms = new Server($loop, 'unix://' . __DIR__ . '/test.ipc'); $comms->on('join', function() { echo "Client joined.\n"; }); $comms->on('part', function() { echo "Client exited.\n"; }); $comms->on('message', function($message) use ($comms) { echo "Client said: $message\n"; $comms->send('...'); }); $comms->listen(); $loop->run();
客户端
use Concerto\Comms\Client; use React\EventLoop\Factory; $loop = Factory::create(); $comms = new Client($loop, 'unix://' . __DIR__ . '/test.ipc'); $comms->on('join', function() { echo "Server joined.\n"; }); $comms->on('part', function() { echo "Server exited.\n"; exit; }); $comms->on('message', function($data) { echo "Server said: $data\n"; }); $comms->send('...'); $comms->connect(); $loop->run();