当前位置: 首页>>代码示例>>PHP>>正文


PHP ZMQSocket::setSockOpt方法代码示例

本文整理汇总了PHP中ZMQSocket::setSockOpt方法的典型用法代码示例。如果您正苦于以下问题:PHP ZMQSocket::setSockOpt方法的具体用法?PHP ZMQSocket::setSockOpt怎么用?PHP ZMQSocket::setSockOpt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ZMQSocket的用法示例。


在下文中一共展示了ZMQSocket::setSockOpt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
 }
开发者ID:zhangjingpu,项目名称:yaf-lib,代码行数:31,代码来源:Madserver.php

示例2: 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);
 }
开发者ID:limitium,项目名称:zmq,代码行数:13,代码来源:PublisherTest.php

示例3: createCollector

 /**
  * @param $context
  * @param $endpoint
  * @return Zmsg
  */
 private function createCollector($context, $endpoint)
 {
     $receiver = new \ZMQSocket($context, \ZMQ::SOCKET_SUB);
     $receiver->setSockOpt(\ZMQ::SOCKOPT_LINGER, 0);
     $receiver->setSockOpt(\ZMQ::SOCKOPT_SUBSCRIBE, "");
     $receiver->bind($endpoint);
     return $receiver;
 }
开发者ID:limitium,项目名称:zmq,代码行数:13,代码来源:LogTest.php

示例4: 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->setSockOpt(\ZMQ::SOCKOPT_LINGER, 0);
     $publisher->bind($endpoint);
     return new Zmsg($publisher);
 }
开发者ID:limitium,项目名称:zmq,代码行数:13,代码来源:SubscriberTest.php

示例5: 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;
 }
开发者ID:mheydt,项目名称:scalr,代码行数:18,代码来源:AsynClient.php

示例6: s_worker_socket

function s_worker_socket($context)
{
    $worker = new ZMQSocket($context, ZMQ::SOCKET_DEALER);
    //  Set random identity to make tracing easier
    $identity = sprintf("%04X-%04X", rand(0, 0x10000), rand(0, 0x10000));
    $worker->setSockOpt(ZMQ::SOCKOPT_IDENTITY, $identity);
    $worker->connect("tcp://localhost:5556");
    //  Configure socket to not wait at close time
    $worker->setSockOpt(ZMQ::SOCKOPT_LINGER, 0);
    //  Tell queue we're ready for work
    printf("I: (%s) worker ready%s", $identity, PHP_EOL);
    $worker->send("READY");
    return array($worker, $identity);
}
开发者ID:inactivist,项目名称:zguide,代码行数:14,代码来源:ppworker.php

示例7: client_task

function client_task()
{
    $context = new ZMQContext();
    $client = new ZMQSocket($context, ZMQ::SOCKET_DEALER);
    //  Generate printable identity for the client
    $identity = sprintf("%04X", rand(0, 0x10000));
    $client->setSockOpt(ZMQ::SOCKOPT_IDENTITY, $identity);
    $client->connect("tcp://localhost:5570");
    $read = $write = array();
    $poll = new ZMQPoll();
    $poll->add($client, ZMQ::POLL_IN);
    $request_nbr = 0;
    while (true) {
        //  Tick once per second, pulling in arriving messages
        for ($centitick = 0; $centitick < 100; $centitick++) {
            $events = $poll->poll($read, $write, 1000);
            $zmsg = new Zmsg($client);
            if ($events) {
                $zmsg->recv();
                printf("%s: %s%s", $identity, $zmsg->body(), PHP_EOL);
            }
        }
        $zmsg = new Zmsg($client);
        $zmsg->body_fmt("request #%d", ++$request_nbr)->send();
    }
}
开发者ID:EnochChen,项目名称:zguide,代码行数:26,代码来源:asyncsrv.php

示例8: receiveMessage

 /**
  * @param string|null $queueId
  * @param int $waitTime
  *
  * @return QueueMessage
  */
 public function receiveMessage($queueId = null, $waitTime = null)
 {
     $queueId = empty($queueId) ? $this->getQueueId() : $queueId;
     $this->setupPullSocket($queueId);
     $this->pull->setSockOpt(\ZMQ::SOCKOPT_RCVTIMEO, isset($waitTime) ? $waitTime : $this->waitTime);
     $message = $this->pull->recv();
     return $this->messageFactory->createMessage($message, $queueId);
 }
开发者ID:silktide,项目名称:queueball-zmq,代码行数:14,代码来源:Queue.php

示例9: client_socket

function client_socket(ZMQContext $context)
{
    echo "I: connecting to server...", PHP_EOL;
    $client = new ZMQSocket($context, ZMQ::SOCKET_REQ);
    $client->connect("tcp://localhost:5555");
    //  Configure socket to not wait at close time
    $client->setSockOpt(ZMQ::SOCKOPT_LINGER, 0);
    return $client;
}
开发者ID:nivertech,项目名称:zguide,代码行数:9,代码来源:lpclient.php

示例10: pushActionResultInfo

 public function pushActionResultInfo(ActionResultingPushDto $resultingPushDto)
 {
     $this->subscriberSocket->setSockOpt(\ZMQ::SOCKOPT_UNSUBSCRIBE, "");
     $this->performerEarlyTerminated->setStandOnSubscription(false);
     $this->logger->debug("Performer was unsubscribed.");
     $this->initOrCheckPushConnection();
     $this->pushSocket->send(serialize($resultingPushDto));
     $this->logger->debug("Performer send actionResulting msg.");
     return null;
 }
开发者ID:jamset,项目名称:publisher-pulsar,代码行数:10,代码来源:Performer.php

示例11: worker_task

function worker_task()
{
    $context = new ZMQContext();
    $worker = new ZMQSocket($context, ZMQ::SOCKET_DEALER);
    $worker->setSockOpt(ZMQ::SOCKOPT_IDENTITY, "W");
    $worker->connect("tcp://localhost:5556");
    while (true) {
        $zmsg = new Zmsg($worker);
        $zmsg->recv();
        $zmsg->send();
    }
}
开发者ID:inactivist,项目名称:zguide,代码行数:12,代码来源:tripping.php

示例12: handlerAction

 public function handlerAction()
 {
     try {
         // setup the ZMQ content so as to avoid issues with conflicts
         $ctx = new \ZMQContext();
         // create a SOCKET_REP server
         $server = new \ZMQSocket($ctx, \ZMQ::SOCKET_REP);
         //  configure the server socket to not wait at close time
         // this is intended to minimise the possibility of messages being received and not handled
         // however as is mentioned in the TODO below they should be handle them explicitly
         $server->setSockOpt(\ZMQ::SOCKOPT_LINGER, 0);
         // bind it to tcp on port 5454
         $server->bind('tcp://*:5454');
         // create a Poll object to enable us to utilize the REQUEST_TIMEOUT functionality
         $poll = new \ZMQPoll();
         $poll->add($server, \ZMQ::POLL_IN);
         // initialise the read/write buffers for polling
         $read = $write = array();
         // get the time that we start the loop
         $start = time();
         do {
             // this instruction will wait for a message or the timeout to occur
             $events = $poll->poll($read, $write, REQUEST_TIMEOUT);
             // @TODO since exiting the loop will happens after this point a race condition exists
             // We need to consider solutions that will ensure ALL messages to $server are processed
             // if the loop will exit after this iteration.
             // one could check the $events variable as this contains the number of events
             // however in this situation we only want to process the $read resources and can
             // just loop through an array (if it is empty nothing will be done)
             foreach ($read as $socket) {
                 $message = $socket->recv();
                 $server->send($message . ' World');
             }
             // ensure that even when a message is processed the handler
             // does not timeout until the REQUEST_TIMEOUT period
             // has elapsed
             $active = time() - $start < REQUEST_TIMEOUT / 1000.0;
         } while ($active);
     } catch (Exception $e) {
         // handle the exception
         // @TODO
     }
     // exit the handler
     die('This handler has timed out');
 }
开发者ID:rhodium289,项目名称:sandbox,代码行数:45,代码来源:ConsumeController.php

示例13: subscriber

function subscriber()
{
    $context = new ZMQContext();
    // Subscribe to everything
    $subscriber = new ZMQSocket($context, ZMQ::SOCKET_SUB);
    $subscriber->connect("tcp://localhost:5556");
    $subscriber->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, "");
    //  Get and process messages
    while (true) {
        $clock = $subscriber->recv();
        //  Suicide snail logic
        if (microtime(true) * 100 - $clock * 100 > MAX_ALLOWED_DELAY) {
            echo "E: subscriber cannot keep up, aborting", PHP_EOL;
            break;
        }
        //  Work for 1 msec plus some random additional time
        usleep(1000 + rand(0, 1000));
    }
}
开发者ID:nivertech,项目名称:zguide,代码行数:19,代码来源:suisnail.php

示例14: ZMQContext

<?php

/*
 *  Durable subscriber
 * @author Ian Barber <ian(dot)barber(at)gmail(dot)com>
 */
$context = new ZMQContext(1);
//  Connect our subscriber socket
$subscriber = new ZMQSocket($context, ZMQ::SOCKET_SUB);
$subscriber->setSockOpt(ZMQ::SOCKOPT_IDENTITY, "Hello");
$subscriber->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, "");
$subscriber->connect("tcp://localhost:5565");
//  Synchronize with publisher
$sync = new ZMQSocket($context, ZMQ::SOCKET_PUSH);
$sync->connect("tcp://localhost:5564");
$sync->send("");
//  Get updates, expect random Ctrl-C death
while (true) {
    $string = $subscriber->recv();
    echo $string, "\n";
    if ($string == "END") {
        break;
    }
}
开发者ID:nivertech,项目名称:zguide,代码行数:24,代码来源:durasub.php

示例15: ZMQContext

<?php

$context = new ZMQContext();
// Socket to talk to server
echo "Collecting updates from weather server...", PHP_EOL;
$subscriber = new ZMQSocket($context, ZMQ::SOCKET_SUB);
$subscriber->connect("tcp://localhost:5556");
$subscriber->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, 'Message');
// Process 100 updates
while (true) {
    print $subscriber->recv();
}
开发者ID:Pync,项目名称:Pync,代码行数:12,代码来源:subscriber.php


注:本文中的ZMQSocket::setSockOpt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。