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


PHP ZMQSocket::bind方法代码示例

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


在下文中一共展示了ZMQSocket::bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initSocket

 private function initSocket()
 {
     $zmq_context = new \ZMQContext();
     $this->zmq_socket = $zmq_context->getSocket(\ZMQ::SOCKET_REP);
     $this->zmq_socket->bind('ipc:///tmp/ebussola-job-schedule.ipc');
     chmod('/tmp/ebussola-job-schedule.ipc', 0777);
 }
开发者ID:ebussola,项目名称:job-schedule,代码行数:7,代码来源:Daemon.php

示例2: __construct

 /**
  * @param string $protocol
  * @param string $encoding
  * @param bool   $synchronous
  * @param array  $endpoint
  */
 public function __construct($protocol, $encoding, $synchronous = false, array $endpoint = [])
 {
     parent::__construct($protocol, $encoding, $synchronous, $endpoint);
     list($type, $dsn, $force, $mode) = array_values($this->endpoint);
     $this->context = new \ZMQContext();
     $this->socket = new \ZMQSocket($this->context, $type);
     $this->socket->bind($dsn, $force);
     $this->mode = $mode;
 }
开发者ID:mihai-stancu,项目名称:rpc-bundle,代码行数:15,代码来源:ZmqConnection.php

示例3: connect

 public function connect()
 {
     $context = new \ZMQContext();
     $socket = new \ZMQSocket($context, \ZMQ::SOCKET_SUB);
     $socket->bind($this->dsn());
     return $socket;
 }
开发者ID:pelim,项目名称:laravel-zmq,代码行数:7,代码来源:ZmqSubscribe.php

示例4: broker_task

function broker_task()
{
    //  Prepare our context and sockets
    $context = new ZMQContext();
    $frontend = new ZMQSocket($context, ZMQ::SOCKET_ROUTER);
    $backend = new ZMQSocket($context, ZMQ::SOCKET_ROUTER);
    $frontend->bind("tcp://*:5555");
    $backend->bind("tcp://*:5556");
    //  Initialize poll set
    $poll = new ZMQPoll();
    $poll->add($frontend, ZMQ::POLL_IN);
    $poll->add($backend, ZMQ::POLL_IN);
    $read = $write = array();
    while (true) {
        $events = $poll->poll($read, $write);
        foreach ($read as $socket) {
            $zmsg = new Zmsg($socket);
            $zmsg->recv();
            if ($socket === $frontend) {
                $zmsg->push("W");
                $zmsg->set_socket($backend)->send();
            } elseif ($socket === $backend) {
                $zmsg->pop();
                $zmsg->push("C");
                $zmsg->set_socket($frontend)->send();
            }
        }
    }
}
开发者ID:inactivist,项目名称:zguide,代码行数:29,代码来源:tripping.php

示例5: collect

 public function collect(OutputInterface $output)
 {
     $context = new \ZMQContext();
     $resultsQueue = new \ZMQSocket($context, \ZMQ::SOCKET_PULL);
     $resultsQueue->bind(Spider::ZMQ_RESULTS_QUEUE_BIND_DSN);
     $statusQueue = new \ZMQSocket($context, \ZMQ::SOCKET_PUSH);
     $statusQueue->bind(Spider::ZMQ_STATUS_QUEUE_BIND_DSN);
     $tstart = microtime(true);
     $collectedResults = 0;
     $expectedResults = PHP_INT_MAX;
     $output->writeln('Collecting Task results');
     while ($collectedResults < $expectedResults) {
         $string = $resultsQueue->recv();
         if ($string === Spider::ZMQ_COMMAND_BATCH_START) {
             //  Wait for start of batch
         } elseif (stripos($string, Spider::ZMQ_COMMAND_BATCH_END) === false) {
             $output->writeln('Got task result: ' . substr($string, 0, 20) . ' ...');
             file_put_contents($this->resultsTargetPath . '/' . md5($string) . '.result', $string);
             // TODO: use Symfony/Filesystem
             $output->writeln('Collected results so far: ' . ++$collectedResults);
         } else {
             $expectedResults = (int) explode('%', $string)[1];
             $output->writeln('[INFO] Trying to collect ' . $expectedResults . ' as requested by Task Loader');
         }
     }
     $tend = microtime(true);
     $totalMsec = ($tend - $tstart) * 1000;
     $output->writeln('Task results collecting finished. Got ' . $collectedResults . ' results');
     $output->writeln("Total elapsed time: {$totalMsec} msec");
     $output->writeln('Sending Task Result Collector info');
     $statusQueue->send($collectedResults);
 }
开发者ID:highestgoodlikewater,项目名称:spider-5,代码行数:32,代码来源:TaskResultCollector.php

示例6: listen

 /**
  * Start the worker and wait for requests
  */
 public function listen()
 {
     $context = new \ZMQContext();
     $server = new \ZMQSocket($context, \ZMQ::SOCKET_PULL);
     $server->bind('tcp://127.0.0.1:' . ($this->defaultPort + $this->client->getId() - 1));
     $this->logger->info('Client worker ' . $this->client . ' is ready');
     while (true) {
         $request = $server->recv();
         $this->logger->debug('Client worker ' . $this->client . ' receiving request : ' . $request);
         // Check if the input is valid, ignore if wrong
         $request = json_decode($request, true);
         if (!$this->isValidInput($request)) {
             $this->logger->error('Client worker ' . $this->client . ' received an invalid input');
             continue;
         }
         try {
             // Call the right method in the client and push to redis the result
             $result = call_user_func_array(array($this->client, $request['command']), $request['parameters']);
         } catch (ClientNotReadyException $e) {
             $this->logger->warning('Client worker ' . $this->client . ' received a request (#' . $request['invokeId'] . ') whereas the client is not ready. This is normal in case of client reconnection process. Ignoring.');
             continue;
         }
         $key = $this->key . '.client.commands.' . $request['invokeId'];
         $this->redis->rpush($key, serialize($result));
         $this->redis->expire($key, $this->expire);
     }
 }
开发者ID:phxlol,项目名称:lol-php-api,代码行数:30,代码来源:ClientWorker.php

示例7: run

 /**
  * Run ZMQ interface for generator
  * 
  * Req-rep pattern; msgs are commands:
  * 
  * GEN    = Generate ID
  * STATUS = Get status string
  */
 public function run()
 {
     $context = new \ZMQContext();
     $receiver = new \ZMQSocket($context, \ZMQ::SOCKET_REP);
     $bindTo = 'tcp://*:' . $this->port;
     echo "Binding to {$bindTo}\n";
     $receiver->bind($bindTo);
     while (TRUE) {
         $msg = $receiver->recv();
         switch ($msg) {
             case 'GEN':
                 try {
                     $response = $this->generator->generate();
                 } catch (\Exception $e) {
                     $response = "ERROR";
                 }
                 break;
             case 'STATUS':
                 $response = json_encode($this->generator->status());
                 break;
             default:
                 $response = 'UNKNOWN COMMAND';
                 break;
         }
         $receiver->send($response);
     }
 }
开发者ID:Minds,项目名称:cruftflake,代码行数:35,代码来源:ZeroMq.php

示例8: init

 /**
  * @return void
  */
 protected function init()
 {
     $this->logger->info("Running " . self::class . " on " . str_replace("\n", "", `hostname; echo ' - ';uname -a;`));
     $this->logger->info("The eviction tick rate is set to {$this->config->getEvictionTicksPerSec()}/second.");
     // Create the event loop
     $this->reactLoop = React\EventLoop\Factory::create();
     // Object pool
     $this->queue = new PriorityHashQueue();
     // In default mode the latest data will be replaced for a given key. In DATA_MODE_APPEND the data will be appended
     // internally and available within the consumer as array (for instance for reducing purposes)
     //$this->queue->setDataMode(PriorityHashQueue::DATA_MODE_APPEND);
     // Setup ZMQ to send evicted objects.
     $this->zmqContext = new React\ZMQ\Context($this->reactLoop);
     $this->logger->info("Binding inbound ZMQ to '{$this->config->getZmqIn()}'.");
     // Receiver queue for incoming objects
     $this->zmqInboundQueue = $this->zmqContext->getSocket(\ZMQ::SOCKET_PULL);
     $this->zmqInboundQueue->bind($this->config->getZmqIn());
     $this->logger->info("Binding outbound ZMQ to '{$this->config->getZmqOut()}'.");
     // Outgoing queue for evicted objects
     $this->zmqOutboundQueue = $this->zmqContext->getSocket(\ZMQ::SOCKET_PUSH);
     $this->zmqOutboundQueue->bind($this->config->getZmqOut());
     // Register events
     $this->registerInboundEvents();
     $this->registerEvictionEvents();
     $this->registerTimedEvents();
 }
开发者ID:awdn,项目名称:vigilant-queue,代码行数:29,代码来源:DeferredQueue.php

示例9: connect

 /**
  * @param \ZMQContext $context
  * @return bool
  */
 public function connect(\ZMQContext $context)
 {
     $this->clientChannel = new \ZMQSocket($context, ZMQ::SOCKET_ROUTER);
     $this->workerChannel = new \ZMQSocket($context, ZMQ::SOCKET_ROUTER);
     try {
         $this->clientChannel->bind("tcp://*:{$this->config->getClientPort()}");
         $this->workerChannel->bind("tcp://*:{$this->config->getWorkerPort()}");
         return true;
     } catch (\ZMQSocketException $e) {
         return false;
     } catch (\ZMQException $e) {
         return false;
     } catch (\Exception $e) {
         return false;
     }
 }
开发者ID:geevcookie,项目名称:zeromq-php-helpers,代码行数:20,代码来源:HeartbeatBroker.php

示例10: 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

示例11: initSockets

 /**
  * @param array[string]string $connUris
  */
 private function initSockets(array $connUris)
 {
     // Create context
     $this->reactLoop = ReactFactory::create();
     /** @var ReactZmqContext|\ZMQContext $reactZmqContext */
     $reactZmqContext = new ReactZmqContext($this->reactLoop);
     $this->hbSocket = $reactZmqContext->getSocket(\ZMQ::SOCKET_REP);
     $this->hbSocket->bind($connUris['hb']);
     $this->iopubSocket = $reactZmqContext->getSocket(\ZMQ::SOCKET_PUB);
     $this->iopubSocket->bind($connUris['iopub']);
     $this->controlSocket = $reactZmqContext->getSocket(\ZMQ::SOCKET_ROUTER);
     $this->controlSocket->bind($connUris['control']);
     $this->stdinSocket = $reactZmqContext->getSocket(\ZMQ::SOCKET_ROUTER);
     $this->stdinSocket->bind($connUris['stdin']);
     $this->shellSocket = $reactZmqContext->getSocket(\ZMQ::SOCKET_ROUTER);
     $this->shellSocket->bind($connUris['shell']);
 }
开发者ID:Litipk,项目名称:Jupyter-PHP,代码行数:20,代码来源:KernelCore.php

示例12: setupPullSocket

 protected function setupPullSocket($queueId)
 {
     $connect = true;
     if (!empty($this->pull)) {
         $endpoints = $this->pull->getendpoints();
         if (!empty($endpoints["bind"][0]) && $endpoints["bind"][0] != $queueId) {
             $this->pull->unbind($endpoints["bind"][0]);
         } else {
             $connect = false;
         }
     } else {
         $this->pull = $this->socketFactory->createPullSocket();
     }
     if ($connect) {
         $this->pull->bind($queueId);
     }
 }
开发者ID:silktide,项目名称:queueball-zmq,代码行数:17,代码来源:Queue.php

示例13: 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

示例14: bind

 /**
  * Binds broker to endpoint
  *
  * We use a single socket for both clients and workers.
  *
  * @param   string   $endpoint
  * @return  Broker
  */
 public function bind($endpoint)
 {
     $this->endpoint = $endpoint;
     $this->socket->bind($this->endpoint);
     if ($this->verbose) {
         $this->log("ZMQDEBUG", "MDP broker/0.1.1 is active at %s", $this->endpoint);
     }
     return $this;
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:17,代码来源:Broker.php

示例15: initSockets

 /**
  * @return null
  */
 protected function initSockets()
 {
     $this->replyToReplyStack = $this->context->getSocket(\ZMQ::SOCKET_REP);
     $this->replyToReplyStack->bind($this->pulsarSocketsParams->getReplyToReplyStackSocketAddress());
     $this->publisher = $this->context->getSocket(\ZMQ::SOCKET_PUB);
     $this->publisher->bind($this->pulsarSocketsParams->getPublishSocketAddress());
     $this->pullActionInfo = $this->context->getSocket(\ZMQ::SOCKET_PULL);
     $this->pullActionInfo->bind($this->pulsarSocketsParams->getPullSocketAddress());
     return null;
 }
开发者ID:jamset,项目名称:publisher-pulsar,代码行数:13,代码来源:Pulsar.php


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