当前位置: 首页>>代码示例>>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;未经允许,请勿转载。