本文整理汇总了PHP中ZMQSocket::getsockopt方法的典型用法代码示例。如果您正苦于以下问题:PHP ZMQSocket::getsockopt方法的具体用法?PHP ZMQSocket::getsockopt怎么用?PHP ZMQSocket::getsockopt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZMQSocket
的用法示例。
在下文中一共展示了ZMQSocket::getsockopt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onZMQR
$context = new ZMQContext();
$sender = new ZMQSocket($context, ZMQ::SOCKET_PUSH);
$sender->bind("tcp://*:5557");
$receiver = new ZMQSocket($context, ZMQ::SOCKET_PULL);
$receiver->bind("tcp://*:5558");
function onZMQR()
{
global $receiver;
$string = $receiver->recv();
echo $string, PHP_EOL;
}
$serv->set(array('worker_num' => 1, 'reactor_num' => 1));
$serv->on('workerStart', function ($serv, $worker_id) {
global $sender;
global $receiver;
$rfd = $receiver->getsockopt(ZMQ::SOCKOPT_FD);
swoole_event_add($rfd, 'onZMQR', NULL, SWOOLE_EVENT_READ);
echo "worker start\n";
});
$serv->on('connect', function ($serv, $fd, $from_id) {
echo "[#" . posix_getpid() . "]\tClient@[{$fd}:{$from_id}]: Connect.\n";
});
$serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) {
$cmd = trim($data);
echo "[#" . posix_getpid() . "]\tClient[{$fd}]: {$data}\n";
if ($cmd == "zmqtest") {
echo 'aaaaaaaaaaaa' . PHP_EOL;
$sender->send("msg to zmq");
}
$serv->send($fd, 'OK' . PHP_EOL);
//$serv->close($fd);