🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# react/zmq # react/zmq **`(要求Workerman版本>=3.3.6)`** ## 安装: ```php composer require react/zmq ``` ## 示例: ```php <?php require_once __DIR__ . '/vendor/autoload.php'; use Workerman\Worker; $consumer = new Worker(); $consumer->onWorkerStart = function() { global $pull; $loop = Worker::getEventLoop(); $context = new React\ZMQ\Context($loop); $pull = $context->getSocket(ZMQ::SOCKET_PULL); $pull->bind('tcp://127.0.0.1:5555'); $pull->on('error', function ($e) { var_dump($e->getMessage()); }); $pull->on('message', function ($msg) { echo "Received: $msg\n"; }); }; Worker::runAll(); ``` ## 文档: <https://github.com/reactphp/zmq> ## 注意: 1、所有的异步编码必须在```onXXX```回调中编写 2、异步客户端需要的```$loop```变量请使用```Worker::getEventLoop();```返回值 **备注** * swoole-worker不支持此组件