當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EventLoop\LoopInterface類代碼示例

本文整理匯總了PHP中React\EventLoop\LoopInterface的典型用法代碼示例。如果您正苦於以下問題:PHP LoopInterface類的具體用法?PHP LoopInterface怎麽用?PHP LoopInterface使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了LoopInterface類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * Create a new file driven handler instance.
  *
  * @param \Illuminate\Filesystem\Filesystem $files
  * @param React\EventLoop\LoopInterface $loop
  * @param string $path
  * 
  * @return void
  */
 public function __construct(Factory $factory, LoopInterface $loop, Server $server, $lifetime)
 {
     $this->factory = $factory;
     $this->lifetime = $lifetime;
     $this->server = $server;
     $this->loop = $loop;
     // PING redis connection every 5 minutes
     // and try to reconnect on connection error
     $this->timer = $loop->addPeriodicTimer(60 * 1, function () use($server) {
         $this->promise->then(function ($client) use($server) {
             $client->PING()->then(function ($pong) use($server) {
                 $server->log('Redis server responded ping with: %s', [$pong]);
                 return $pong == 'PONG';
             }, function ($e) {
                 return $this->reconnectByError($e);
             });
         });
     });
     // server statistics for redis connection
     $this->loop->addPeriodicTimer(60 * 30, function () {
         $this->server->log('Server statistics to the last 30 minutes.');
         $this->server->log('Best time of %fs, poor time of %fs and a average of %f seconds for total %d requests.', array_values($this->statistics));
         $this->statistics = array('best' => 0, 'poor' => 0, 'avg' => 0, 'total' => 0);
     });
 }
開發者ID:irto,項目名稱:oauth2-proxy,代碼行數:34,代碼來源:AsyncRedisSessionHandler.php

示例2: __construct

 public function __construct(TransportInterface $carrierProtocol, LoopInterface $loop, LoggerInterface $logger)
 {
     $that = $this;
     $this->logger = $logger;
     $this->loop = $loop;
     $this->carrierProtocol = $carrierProtocol;
     $this->actionEmitter = new EventEmitter();
     $deferreds =& $this->deferred;
     $timers =& $this->timers;
     $carrierProtocol->on("message", function (MessageInterface $message) use(&$deferreds, &$timers, &$loop, $that, $logger) {
         $string = $message->getData();
         try {
             $jsonMessage = RemoteEventMessage::fromJson($string);
             $tag = $jsonMessage->getTag();
             if (array_key_exists($tag, $deferreds)) {
                 $deferred = $deferreds[$tag];
                 unset($deferreds[$tag]);
                 if (array_key_exists($tag, $timers)) {
                     $loop->cancelTimer($timers[$tag]);
                     unset($timers[$tag]);
                 }
                 $deferred->resolve($jsonMessage);
             } else {
                 $that->remoteEvent()->emit($jsonMessage->getEvent(), array($jsonMessage));
             }
             $that->emit("message", array($jsonMessage));
         } catch (\Exception $e) {
             $logger->err("Exception while parsing JsonMessage: " . $e->getMessage());
         }
     });
 }
開發者ID:rb-cohen,項目名稱:phpws,代碼行數:31,代碼來源:RemoteEventTransport.php

示例3: runDaemon

 /**
  * Starts downloader in daemon mode, awaiting for future tasks
  * @todo Locks and signal processing
  *
  * @param EventLoop\LoopInterface $loop A loop, worker is run on
  */
 public function runDaemon(EventLoop\LoopInterface $loop)
 {
     $loop->addPeriodicTimer($this->tick, function ($timer) use($loop) {
         $this->run($loop, $this->limit);
     });
     $loop->run();
 }
開發者ID:helminster,項目名稱:imgloader,代碼行數:13,代碼來源:Worker.php

示例4:

 function it_adds_a_read_stream($socket, ChannelInterface $channel, ConnectionInterface $connection, LoopInterface $loop)
 {
     $channel->getConnection()->willReturn($connection);
     $connection->getSocket()->willReturn($socket);
     $loop->addReadStream($socket, [$this, 'wait'])->shouldBeCalled();
     $this->beConstructedWith($channel, $loop);
 }
開發者ID:mbfisher,項目名稱:react-amqp,代碼行數:7,代碼來源:AmqpConsumerSpec.php

示例5: __construct

 public function __construct(LoopInterface $loop, EventEmitter $emit, \SplObjectStorage $clients, RoundProcessor $roundProcessor, EngineHelper $helper, $time = 60, $debug = false)
 {
     $this->debug = $debug;
     $this->helper = $helper;
     $this->emit = $emit;
     $this->loop = $loop;
     $this->roundTimer = new RoundTimer($loop, $emit);
     $this->roundNumber = 0;
     $this->clients = $clients;
     $this->disconnected = new \SplObjectStorage();
     $this->time = $time;
     $that = $this;
     $this->say = new Say($this->clients);
     $this->roundProcessor = $roundProcessor;
     $players = new Say($this->clients);
     // Setup listeners on the roundTimer object.
     $emit->on('GAME.COUNTDOWN', function () use($that) {
         if ($this->playerCount !== $this->clients->count()) {
             $this->playerCount = $this->clients->count();
             $this->say->to($this->clients)->that(Say::TICK, ["players" => $this->playerCount]);
         }
     });
     // Setup listeners on the roundTimer object.
     $emit->on('GAME.COUNTDOWN_END', function () use($that, $loop, $emit) {
         $this->say->to($this->clients)->that(Say::GAME_STARTING, ["players" => $this->clients->count()]);
         $this->setGameStarted(true);
         $loop->addTimer(3, function () use($loop, $emit) {
             $this->startRound($loop, $emit);
         });
     });
     $this->roundTimer->startCountDown($this->time);
 }
開發者ID:Techbot,項目名稱:ratchet-based-game,代碼行數:32,代碼來源:gameengine.php

示例6: __construct

 /**
  * Create a new event pusher handler
  */
 public function __construct(LoopInterface $loop, OutputInterface $output = null)
 {
     $this->loop = $loop;
     $this->output = $output;
     $this->clients = new \SplObjectStorage();
     $this->subscriber = \Service::getContainer()->get('kernel.subscriber.bzion_subscriber');
     // Ping timer
     $loop->addPeriodicTimer(self::KEEP_ALIVE, array($this, 'ping'));
 }
開發者ID:blast007,項目名稱:bzion,代碼行數:12,代碼來源:EventPusher.php

示例7: __construct

 public function __construct(LoopInterface $loop)
 {
     $bspcProcess = proc_open('pactl subscribe', [['pipe', 'r'], ['pipe', 'w']], $pipes);
     $bspcStdout = new Stream($pipes[1], $loop);
     $bspcStdout->on('data', [$this, 'onUpdate']);
     $loop->addTimer(0, function () {
         $this->queryData();
     });
 }
開發者ID:mkraemer,項目名稱:php-panel,代碼行數:9,代碼來源:Sound.php

示例8: __construct

 public function __construct(LoopInterface $loop, FrameBuffer $frameBuffer, ContainerInterface $container)
 {
     $this->loop = $loop;
     $this->frameBuffer = $frameBuffer;
     $this->container = $container;
     $this->connections = new \SplObjectStorage();
     $fps = (double) $container->get('server.fps');
     $this->update_timer = $this->loop->addPeriodicTimer(1.0 / $fps, [$this, 'onFrameUpdate']);
     $this->switchToGameLoop($container->get(TestImageScreen::class));
 }
開發者ID:hackheim,項目名稱:pixelpong,代碼行數:10,代碼來源:GameServer.php

示例9: __construct

 /**
  * NewEventLoopScheduler constructor.
  * @param callable|LoopInterface $timerCallableOrLoop
  */
 public function __construct($timerCallableOrLoop)
 {
     // passing a loop directly into the scheduler will be deprecated in the next major release
     $this->timerCallable = $timerCallableOrLoop instanceof LoopInterface ? function ($ms, $callable) use($timerCallableOrLoop) {
         $timerCallableOrLoop->addTimer($ms / 1000, $callable);
     } : $timerCallableOrLoop;
     parent::__construct($this->now(), function ($a, $b) {
         return $a - $b;
     });
 }
開發者ID:ReactiveX,項目名稱:RxPHP,代碼行數:14,代碼來源:EventLoopScheduler.php

示例10: start

 /**
  * Start the HTTP Server
  */
 public function start()
 {
     $this->httpServer->on('request', [$this, 'handleRequest']);
     $this->logger->info("Server is listening at " . $this->configuration['listen']['host'] . ":" . $this->configuration['listen']['port']);
     $this->socketServer->listen($this->configuration['listen']['port'], $this->configuration['listen']['host']);
     $this->eventLoop->run();
 }
開發者ID:thinframe,項目名稱:server,代碼行數:10,代碼來源:Server.php

示例11: start

 /**
  * Adds timer to Loop queue
  *
  * @param float $interval
  * @return TimerInterface
  */
 public function start($interval = self::DEFAULT_INTERVAL)
 {
     if ($this->timer) {
         $this->stop();
     }
     return $this->timer = $this->loop->addPeriodicTimer($interval, $this);
 }
開發者ID:mkraemer,項目名稱:react-pcntl,代碼行數:13,代碼來源:PCNTL.php

示例12: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->client->getUsers()->then(function ($users) use($output) {
         $this->importUsers($users, $output);
     });
     $this->loop->run();
 }
開發者ID:vincecore,項目名稱:sharemonkey-bundle,代碼行數:7,代碼來源:ImportSlackUsersCommand.php

示例13: write

 /**
  * Listen for exit command and terminate
  * the event loop
  *
  * @param string $data
  * @return void
  */
 public function write($data)
 {
     if (trim($data) === self::EXIT_CMD) {
         $this->loop->stop();
         $this->close();
     }
 }
開發者ID:epfremmer,項目名稱:PHP-Weekly-Issue25,代碼行數:14,代碼來源:QuitterStream.php

示例14: getStatus

 public function getStatus(callable $callback)
 {
     $this->request('status', [], function ($result) use($callback) {
         $callback(json_decode($result, true));
     });
     $this->loop->run();
 }
開發者ID:php-pm,項目名稱:php-pm,代碼行數:7,代碼來源:Client.php

示例15: close

 /**
  *
  */
 public function close()
 {
     $this->loop->removeReadStream($this->socket);
     if (is_resource($this->socket)) {
         fclose($this->socket);
     }
     $this->notifyCompleted();
 }
開發者ID:domraider,項目名稱:rxnet,代碼行數:11,代碼來源:Datagram.php


注:本文中的React\EventLoop\LoopInterface類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。