本文整理汇总了PHP中ZMQSocket::sendmulti方法的典型用法代码示例。如果您正苦于以下问题:PHP ZMQSocket::sendmulti方法的具体用法?PHP ZMQSocket::sendmulti怎么用?PHP ZMQSocket::sendmulti使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZMQSocket
的用法示例。
在下文中一共展示了ZMQSocket::sendmulti方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mainAction
public function mainAction()
{
echo "Madserver\n";
$context = new ZMQContext();
$sub_socket = new ZMQSocket($context, ZMQ::SOCKET_SUB);
$sub_socket->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, "");
$sub_socket->setSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE, 0);
$sub_socket->setSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_IDLE, 10);
$sub_socket->setSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_CNT, 2);
$sub_socket->setSockOpt(ZMQ::SOCKOPT_TCP_KEEPALIVE_INTVL, 5);
$sub_socket->connect("tcp://127.0.0.1:5557");
$snapshot = new ZMQSocket($context, ZMQ::SOCKET_DEALER);
$snapshot->connect("tcp://127.0.0.1:5556");
$sequence = 1;
$snapshot->sendmulti(array("ICANHAZ?", self::SUBTREE), ZMQ::MODE_SNDMORE);
while (1) {
$kvmsg = new Zmq_Kvmsg($sequence);
$kvmsg->recv($snapshot);
if ($kvmsg->key() == "KTHXBAI") {
echo "I: received snapshot=" . $kvmsg->sequence() . "\n";
break;
}
}
while (1) {
$kvmsg = new Zmq_Kvmsg($sequence);
$kvmsg->recv($sub_socket);
echo "I: start receive sub=" . $kvmsg->sequence() . "\n";
$kvmsg->dump();
}
return false;
}
示例2: handleWriteEvent
/**
* Handle ZMQ Write Event.
*/
public function handleWriteEvent()
{
foreach ($this->messages as $i => $message) {
try {
$message = (array) $message;
$sent = (bool) $this->socket->sendmulti($message, ZMQ::MODE_DONTWAIT);
unset($this->messages[$i]);
if (0 === count($this->messages)) {
$this->loop->removeWriteStream($this->fd);
$this->listening = false;
$this->emit('end');
}
} catch (ZMQSocketException $ex) {
$this->emit('error', [$ex]);
}
}
}