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


PHP ZMQSocket::send方法代码示例

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


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

示例1: send

 /**
  * @param string $message
  * @return mixed
  */
 public function send($message)
 {
     if ($this->isVerbose()) {
         $this->logger->debug("Sending message: " . $message);
     }
     $this->socket->send($message);
 }
开发者ID:awdn,项目名称:vigilant-queue,代码行数:11,代码来源:Client.php

示例2: client_task

function client_task()
{
    $context = new ZMQContext();
    $client = new ZMQSocket($context, ZMQ::SOCKET_DEALER);
    $client->setSockOpt(ZMQ::SOCKOPT_IDENTITY, "C");
    $client->connect("tcp://localhost:5555");
    echo "Setting up test...", PHP_EOL;
    usleep(10000);
    echo "Synchronous round-trip test...", PHP_EOL;
    $start = microtime(true);
    $text = "HELLO";
    for ($requests = 0; $requests < 10000; $requests++) {
        $client->send($text);
        $msg = $client->recv();
    }
    printf(" %d calls/second%s", 1000 * 10000 / (int) ((microtime(true) - $start) * 1000), PHP_EOL);
    echo "Asynchronous round-trip test...", PHP_EOL;
    $start = microtime(true);
    for ($requests = 0; $requests < 100000; $requests++) {
        $client->send($text);
    }
    for ($requests = 0; $requests < 100000; $requests++) {
        $client->recv();
    }
    printf(" %d calls/second%s", 1000 * 100000 / (int) ((microtime(true) - $start) * 1000), PHP_EOL);
}
开发者ID:inactivist,项目名称:zguide,代码行数:26,代码来源:tripping.php

示例3: notify

 /**
  * Notifies the task manager given a message constant, see MESSAGE_* constants.
  *
  * @param string $message
  *
  * @return mixed|null The return value of the task manager.
  *
  * @throws RuntimeException in case notification did not occur within the timeout.
  */
 public function notify($message)
 {
     try {
         $command = $this->createCommand($message);
         $this->socket->send($command);
         $result = false;
         $limit = microtime(true) + $this->timeout;
         while (microtime(true) < $limit && false === ($result = $this->socket->recv(\ZMQ::MODE_NOBLOCK))) {
             usleep(1000);
         }
         if (false === $result) {
             $this->logger->error(sprintf('Unable to notify the task manager with message "%s" within timeout of %d seconds', $message, $this->timeout));
             throw new RuntimeException('Unable to retrieve information.');
         }
         $data = @json_decode($result, true);
         if (JSON_ERROR_NONE !== json_last_error()) {
             throw new RuntimeException('Invalid task manager response : invalid JSON.');
         }
         if (!isset($data['reply']) || !isset($data['request']) || $command !== $data['request']) {
             throw new RuntimeException('Invalid task manager response : missing fields.');
         }
         return $data['reply'];
     } catch (\ZMQSocketException $e) {
         $this->logger->error(sprintf('Unable to notify the task manager with message "%s" within timeout of %d seconds', $message, $this->timeout), ['exception' => $e]);
         throw new RuntimeException('Unable to retrieve information.', $e->getCode(), $e);
     }
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:36,代码来源:Notifier.php

示例4: 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);
         }
     }
 }
开发者ID:highestgoodlikewater,项目名称:spider-5,代码行数:28,代码来源:HttpWorker.php

示例5: write

 /**
  * {@inheritDoc}
  */
 protected function write(array $record)
 {
     if ($this->multipart) {
         $this->zmqSocket->send($record['channel'], $this->zmqMode);
         $this->zmqSocket->send($record['formatted']);
     } else {
         $this->zmqSocket->send($record["formatted"], $this->zmqMode);
     }
 }
开发者ID:websoftwares,项目名称:MonologZMQHandler,代码行数:12,代码来源:ZMQHandler.php

示例6: 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);
 }
开发者ID:sandrokeil,项目名称:psb-zeromq-producer,代码行数:15,代码来源:ZeroMQSocket.php

示例7: send

 /**
  * Sends message to socket.
  *
  * @param   boolean $clear optional Whether it shoud destroy message parts
  * @return  Zmsg
  * @throws  \Exception
  */
 public function send($clear = true)
 {
     if (!isset($this->socket)) {
         throw new \Exception("No socket supplied");
     }
     $count = count($this->parts);
     foreach ($this->parts as $part) {
         $this->socket->send($part, --$count ? \ZMQ::MODE_SNDMORE : null);
     }
     if ($clear) {
         unset($this->parts);
         $this->parts = [];
     }
     return $this;
 }
开发者ID:mheydt,项目名称:scalr,代码行数:22,代码来源:Zmsg.php

示例8: pushReadyToGetSubscriptionMsg

 /**
  * @return null
  */
 public function pushReadyToGetSubscriptionMsg()
 {
     $this->initOrCheckPushConnection();
     $this->pushSocket->send(serialize(new ReadyToGetSubscriptionMsg()));
     $this->logger->debug("Performer send that ready to get subscription msg.");
     return null;
 }
开发者ID:jamset,项目名称:publisher-pulsar,代码行数:10,代码来源:Performer.php

示例9: startStackWork

 /**
  * @return null
  */
 public function startStackWork()
 {
     $getTaskDto = new ReplyStackToPulsarGetTaskRequestDto();
     $considerMeAsSubscriber = 0;
     while (true) {
         //$this->logger->debug("Start ReplyStack while.");
         $this->pulsarRequestSocket->send(serialize($getTaskDto));
         /**Blocking wait reply from Pulsar
          * @var PulsarToReplyStackReplyDto $pulsarToReplyStackReplyDto
          */
         $pulsarToReplyStackReplyDto = unserialize($this->pulsarRequestSocket->recv());
         //$this->logger->debug("REPLY STACK asked to prepare subscribers: " . $pulsarToReplyStackReplyDto->getSubscribersNumber());
         for ($i = 1; $i <= $pulsarToReplyStackReplyDto->getSubscribersNumber(); $i++) {
             $preparingDto = unserialize($this->performersReplySocket->recv());
             //$this->logger->debug("REPLY STACK: receive request $i");
             if ($preparingDto instanceof PreparingRequestDto) {
                 $considerMeAsSubscriber++;
                 //$this->logger->debug("REPLY STACK: considerMeAsSubscriber: $considerMeAsSubscriber");
                 $this->performersReplySocket->send(serialize($pulsarToReplyStackReplyDto->getDtoToTransfer()));
             }
         }
         //$this->logger->debug("REPLY STACK prepared subscribers: " . $considerMeAsSubscriber);
         $replyStackResult = new ReplyStackToPulsarReturnResultRequestDto();
         $replyStackResult->setConsiderMeAsSubscriber($considerMeAsSubscriber);
         $this->pulsarRequestSocket->send(serialize($replyStackResult));
         //$this->logger->debug("Wait finishing message from Pulsar.");
         $this->pulsarRequestSocket->recv();
         //$this->logger->debug("Got finish message from Pulsar.");
         $considerMeAsSubscriber = 0;
         //$this->logger->debug("Finish ReplyStack while.");
     }
     return null;
 }
开发者ID:jamset,项目名称:publisher-pulsar,代码行数:36,代码来源:ReplyStack.php

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

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

示例12: 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;
            }
        }
    }
}
开发者ID:nivertech,项目名称:zguide,代码行数:35,代码来源:peering3.php

示例13: checkForExternalCommand

 private function checkForExternalCommand()
 {
     $cmd = $this->zmq_socket->recv(\ZMQ::MODE_NOBLOCK);
     if ($cmd != null) {
         switch ($cmd) {
             case 'refresh jobs':
                 $this->jobs = $this->schedule->getAllJobs();
                 $this->zmq_socket->send(1, \ZMQ::MODE_NOBLOCK);
                 break;
             case 'get loaded jobs':
                 $data = array();
                 foreach ($this->jobs as $job) {
                     $data[] = (array) $job;
                 }
                 $this->zmq_socket->send(serialize($data), \ZMQ::MODE_NOBLOCK);
                 break;
         }
     }
 }
开发者ID:ebussola,项目名称:job-schedule,代码行数:19,代码来源:Daemon.php

示例14: send

 /**
  * @param string          $commandName
  * @param array           $parameters
  * @param int|string|null $invokeId
  *
  * @return int|string
  */
 protected function send($commandName, array $parameters = array(), $invokeId = null)
 {
     if (null == $invokeId) {
         $invokeId = $this->redis->incr($this->getKey('invokeId'));
     }
     $nextAvailableTime = (double) ConfigurationLoader::get('client.request.overload.available');
     $this->lastCall = microtime(true) + $nextAvailableTime;
     $this->con->send(json_encode(['invokeId' => $invokeId, 'command' => $commandName, 'parameters' => $parameters]), \ZMQ::MODE_DONTWAIT);
     return $invokeId;
 }
开发者ID:phxlol,项目名称:lol-php-api,代码行数:17,代码来源:LOLClientAsync.php

示例15: client_thread

function client_thread()
{
    $context = new ZMQContext();
    $client = new ZMQSocket($context, ZMQ::SOCKET_REQ);
    $client->connect("ipc://frontend.ipc");
    //  Send request, get reply
    $client->send("HELLO");
    $reply = $client->recv();
    printf("Client: %s%s", $reply, PHP_EOL);
}
开发者ID:inactivist,项目名称:zguide,代码行数:10,代码来源:lbbroker.php


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