本文整理汇总了PHP中ZMQSocket::connect方法的典型用法代码示例。如果您正苦于以下问题:PHP ZMQSocket::connect方法的具体用法?PHP ZMQSocket::connect怎么用?PHP ZMQSocket::connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZMQSocket
的用法示例。
在下文中一共展示了ZMQSocket::connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
/**
* @return void
*/
public function connect()
{
$this->context = new \ZMQContext(1);
$this->socket = new \ZMQSocket($this->context, \ZMQ::SOCKET_PUSH);
$this->logger->info("Connecting to server inbound queue on ZMQ '{$this->getZmq()}'.");
$this->socket->connect($this->getZmq());
}
示例2: connectToZMQ
/**
* Connect to ZMQ and set socket
*
* @return ZMQ $socket instance
*/
protected function connectToZMQ()
{
$context = \App::make('ZMQContext');
$this->socket = $context->getSocket(\ZMQ::SOCKET_PUSH, \Config::get('larapush::persistent_socket_name'));
$this->socket->connect($this->getPusherConnect());
return $this->socket;
}
示例3: __construct
public function __construct(CoffeeService $service)
{
$this->service = $service;
$context = new ZMQContext();
$this->socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'pusher');
$this->socket->connect('tcp://127.0.0.1:4444');
}
示例4: getSocket
/**
* @return \ZMQSocket
*/
private function getSocket()
{
if (null == $this->pushSocket) {
$this->pushSocket = $this->context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher');
$this->pushSocket->connect("tcp://localhost:5555");
}
return $this->pushSocket;
}
示例5: send
/**
* @param string|array $message
* @param int $mode
*/
public function send($message, $mode = 0)
{
if (false === $this->connected) {
$connectedTo = $this->socket->getEndpoints();
if (!in_array($this->dsn, $connectedTo)) {
$this->socket->connect($this->dsn);
}
$this->connected = true;
}
$this->socket->send($message, $mode);
}
示例6: connect
private function connect($publisherEndpoint)
{
if ($this->frontedSocket) {
$this->poll->remove($this->frontedSocket);
unset($this->frontedSocket);
}
$this->frontedSocket = $this->createSocket(\ZMQ::SOCKET_SUB, [\ZMQ::SOCKOPT_LINGER => 0, \ZMQ::SOCKOPT_SUBSCRIBE => ""], true);
$this->frontedSocket->connect($publisherEndpoint);
$this->poll->add($this->frontedSocket, \ZMQ::POLL_IN);
if ($this->verbose) {
printf("I: Connecting to publisher at %s... %s", $publisherEndpoint, PHP_EOL);
}
}
示例7: connect
/**
* Connects or reconnect to broker
*
* @return AsynClient
*/
public function connect()
{
if ($this->client) {
unset($this->client);
}
$this->client = new ZMQSocket($this->context, ZMQ::SOCKET_DEALER);
$this->client->setSockOpt(ZMQ::SOCKOPT_LINGER, 0);
$this->client->connect($this->broker);
if ($this->verbose) {
$this->log("ZMQDEBUG", "connecting to broker at %s...", $this->broker);
}
return $this;
}
示例8: createPublisher
/**
* @param $context
* @param $endpoint
* @return Zmsg
*/
private function createPublisher($context, $endpoint)
{
$publisher = new \ZMQSocket($context, \ZMQ::SOCKET_PUB);
$publisher->setSockOpt(\ZMQ::SOCKOPT_SNDHWM, 1);
$publisher->connect($endpoint);
return new Zmsg($publisher);
}
示例9: run
public function run(OutputInterface $output)
{
$context = new \ZMQContext();
$tasksQueue = new \ZMQSocket($context, \ZMQ::SOCKET_PULL);
$tasksQueue->connect(Spider::ZMQ_TASKS_QUEUE_DSN);
$resultsQueue = new \ZMQSocket($context, \ZMQ::SOCKET_PUSH);
$resultsQueue->connect(Spider::ZMQ_RESULTS_QUEUE_DSN);
$output->writeln('HTTP Worker is waiting for tasks');
while (true) {
$string = $tasksQueue->recv();
if ($string === Spider::ZMQ_COMMAND_BATCH_START) {
$resultsQueue->send($string);
} elseif (stripos($string, Spider::ZMQ_COMMAND_BATCH_END) !== false) {
// send info for result collector how many results it should expect
$resultsQueue->send($string);
} elseif ($string === Spider::ZMQ_COMMAND_WORKER_QUIT) {
$output->writeln('No more work. Worker stops now.');
break;
// no more work
} else {
$output->writeln('Fetching data from URI: ' . $string);
$userData = file_get_contents($string);
// TODO: use Guzzle
$output->writeln('Sending result for URI: ' . $string);
$resultsQueue->send($userData);
}
}
}
示例10: 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;
}
示例11: connectZmq
/**
* Connect to socket
*
* @return ZMQSocket instance
*/
protected function connectZmq()
{
$context = new \ZMQContext();
$this->socket = $context->getSocket(\ZMQ::SOCKET_PUSH, \Config::get('latchet::socketPushId', sprintf('latchet.push.%s', \App::environment())));
$this->socket->connect("tcp://localhost:" . \Config::get('latchet::zmqPort'));
return $this->socket;
}
示例12: initZmq
/**
* @param LoopInterface $loop
*/
public function initZmq(LoopInterface $loop)
{
/** @var \ZMQContext $context */
$context = new \React\ZMQ\Context($loop);
$this->listener = $context->getSocket(\ZMQ::SOCKET_PUSH);
$this->listener->connect('tcp://127.0.0.1:5559');
$this->receiver = $context->getSocket(\ZMQ::SOCKET_PULL);
$this->receiver->connect('tcp://127.0.0.1:5557');
$this->receiver->on('message', function ($msg) {
$message = json_decode($msg, true);
if (is_array($message) && isset($message['outputs']) && is_array($message['outputs'])) {
$cumulative = array();
foreach ($message['outputs'] as $output) {
$script = pack("H*", $output['script']);
if (!isset($cumulative[$script])) {
$cumulative[$script] = $output['value'];
} else {
$cumulative[$script] += $output['value'];
}
}
$message['requirements'] = $cumulative;
$this->contracts[$message['slug']] = $message;
echo "New contract: " . $msg . "\n";
}
});
}
示例13: client_thread
function client_thread($self)
{
$context = new ZMQContext();
$client = new ZMQSocket($context, ZMQ::SOCKET_REQ);
$endpoint = sprintf("ipc://%s-localfe.ipc", $self);
$client->connect($endpoint);
$monitor = new ZMQSocket($context, ZMQ::SOCKET_PUSH);
$endpoint = sprintf("ipc://%s-monitor.ipc", $self);
$monitor->connect($endpoint);
$readable = $writeable = array();
while (true) {
sleep(mt_rand(0, 4));
$burst = mt_rand(1, 14);
while ($burst--) {
// Send request with random hex ID
$task_id = sprintf("%04X", mt_rand(0, 10000));
$client->send($task_id);
// Wait max ten seconds for a reply, then complain
$poll = new ZMQPoll();
$poll->add($client, ZMQ::POLL_IN);
$events = $poll->poll($readable, $writeable, 10 * 1000000);
if ($events > 0) {
foreach ($readable as $socket) {
$zmsg = new Zmsg($socket);
$zmsg->recv();
// Worker is supposed to answer us with our task id
assert($zmsg->body() == $task_id);
}
} else {
$monitor->send(sprintf("E: CLIENT EXIT - lost task %s", $task_id));
exit;
}
}
}
}
示例14: createSubscriber
/**
* @param $context
* @param $endpoint
* @return Zmsg
*/
private function createSubscriber($context, $endpoint)
{
$receiver = new \ZMQSocket($context, \ZMQ::SOCKET_SUB);
$receiver->setSockOpt(\ZMQ::SOCKOPT_LINGER, 0);
$receiver->setSockOpt(\ZMQ::SOCKOPT_SUBSCRIBE, "");
$receiver->connect($endpoint);
return new Zmsg($receiver);
}
示例15: setupPushSocket
protected function setupPushSocket($queueId)
{
$connect = true;
if (!empty($this->push)) {
$endpoints = $this->push->getendpoints();
if (!empty($endpoints["connect"][0]) && $endpoints["connect"][0] != $queueId) {
$this->push->disconnect($endpoints["connect"][0]);
} else {
$connect = false;
}
} else {
$this->push = $this->socketFactory->createPushSocket();
}
if ($connect) {
$this->push->connect($queueId);
}
}