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


PHP LoopInterface::addPeriodicTimer方法代码示例

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


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

示例1: build

 /**
  * Builds internal request handling objects.
  *
  * @return $this
  */
 public function build()
 {
     if ($this->cache) {
         $loader = new ClassLoader();
         if ($this->apc) {
             $apcLoader = new ApcClassLoader(sha1('ReactServer'), $loader);
             $loader->unregister();
             $apcLoader->register(true);
         }
     }
     require_once $this->root_dir . '/AppKernel.php';
     define('KERNEL_ROOT', $this->root_dir);
     $kernel = new ReactKernel($this->env, $this->env === 'dev' ? true : false);
     $this->loop = Factory::create();
     // TODO make config for this part
     if (class_exists('\\Doctrine\\DBAL\\Driver\\PingableConnection')) {
         $this->loop->addPeriodicTimer(15, function () use($kernel) {
             foreach ($kernel->getContainer()->get('doctrine')->getConnections() as $connection) {
                 if ($connection instanceof \Doctrine\DBAL\Driver\PingableConnection) {
                     $connection->ping();
                 }
             }
         });
     }
     $this->socket = new SocketServer($this->loop);
     $http = new HttpServer($this->socket, $this->loop);
     $http->on('request', $this->handleRequest($kernel));
     return $this;
 }
开发者ID:itscaro,项目名称:react-bundle,代码行数:34,代码来源:Server.php

示例2: __construct

 public function __construct(AMQPQueue $queue, LoopInterface $loop, Serializer $serializer)
 {
     $this->queue = $queue;
     $this->loop = $loop;
     $this->timer = $this->loop->addPeriodicTimer(1, [$this, 'listen']);
     $this->serializer = $serializer;
 }
开发者ID:carlosbuenosvinos,项目名称:ddd,代码行数:7,代码来源:AmqpExchangeListener.php

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

示例4: addPeriodicTimer

 /**
  * @param TopicInterface $topic
  * @param string         $name
  * @param int|float      $timeout
  * @param mixed          $callback
  */
 public function addPeriodicTimer(TopicInterface $topic, $name, $timeout, $callback)
 {
     $namespace = spl_object_hash($topic);
     if (!isset($this->registry[$namespace])) {
         $this->registry[$namespace] = [];
     }
     $this->registry[$namespace][$name] = $this->loop->addPeriodicTimer($timeout, $callback);
 }
开发者ID:rsrodrig,项目名称:MeetMeSoftware,代码行数:14,代码来源:TopicPeriodicTimer.php

示例5: __construct

 /**
  * ShortUUID constructor.
  *
  * @param LoopInterface $loop
  * @param int           $generator_id
  */
 public function __construct(LoopInterface $loop, $generator_id = 1)
 {
     $this->loop = $loop;
     $this->generator_id = (int) $generator_id;
     $this->resetCounter();
     // reset the counter every 1 milliseconds
     $this->loop->addPeriodicTimer(0.001, array($this, 'resetCounter'));
 }
开发者ID:vantt,项目名称:short-flake,代码行数:14,代码来源:IdGenerator.php

示例6: __construct

 /**
  * Constructor. Stores the message queue and the event loop for use.
  *
  * @param AMQPQueue                     $queue    Message queue
  * @param React\EventLoop\LoopInterface $loop     Event loop
  * @param float                         $interval Interval to check for new messages
  * @param int                           $max      Max number of messages to consume in one go
  */
 public function __construct(AMQPQueue $queue, LoopInterface $loop, $interval, $max = null)
 {
     $this->queue = $queue;
     $this->loop = $loop;
     $this->max = $max;
     $this->timer = $this->loop->addPeriodicTimer($interval, $this);
     $this->on('close_amqp_consumer', [$this, 'close']);
 }
开发者ID:GeniusesOfSymfony,项目名称:ReactAMQP,代码行数:16,代码来源:Consumer.php

示例7: onSubscribeNewTopic

 /**
  * Start the keep alive timer when the first client subscribes
  *
  * @param CakeEvent $event
  */
 public function onSubscribeNewTopic(CakeEvent $event)
 {
     if (Configure::read('Ratchet.Connection.keepaliveInterval') > 0) {
         $this->__timer = $this->__loop->addPeriodicTimer(Configure::read('Ratchet.Connection.keepaliveInterval'), function () use($event) {
             $event->subject()->broadcast('Rachet.connection.keepAlive', ['ping']);
         });
         $event->subject()->broadcast('Rachet.connection.keepAlive', ['ping']);
     }
 }
开发者ID:schnauss,项目名称:Ratchet,代码行数:14,代码来源:RatchetKeepAliveListener.php

示例8: init

 public function init(LoopInterface $loop = null)
 {
     $this->loop = is_null($loop) ? \React\EventLoop\Factory::create() : $loop;
     $this->loop->addPeriodicTimer(0.1, array($this, 'checkSchedule'));
     $this->bindSignals();
     $this->loop->addPeriodicTimer(1, function () {
         pcntl_signal_dispatch();
     });
 }
开发者ID:pilat,项目名称:daemonizer,代码行数:9,代码来源:ChildController.php

示例9: __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

示例10: addLookupTimer

 protected function addLookupTimer()
 {
     $this->loop->addPeriodicTimer(30, function () {
         $addresses = $this->lookup->lookup();
         foreach ($addresses as $address) {
             $key = $address['ip'] . ':' . $address['port'];
         }
         // ... refresh connection
     });
 }
开发者ID:huyanping,项目名称:phpnsq,代码行数:10,代码来源:Consumer.php

示例11: start

 public function start()
 {
     $this->bindSignals();
     //master process shutdown request handler
     $this->loop->addPeriodicTimer(1, function () {
         pcntl_signal_dispatch();
     });
     foreach ($this->daemons as $daemon) {
         $this->daemons[$daemon] = $this->newInstance($daemon);
     }
 }
开发者ID:pilat,项目名称:daemonizer,代码行数:11,代码来源:MasterController.php

示例12: handle

 public function handle($id)
 {
     $this->id = $id;
     printf("Will connect on %s\n", $this->ip);
     $this->dealer->connect($this->ip, sprintf('dealer-%s', $this->id));
     $this->dealer->filter(function (Event $event) {
         return $event->is("/response/foo");
     })->subscribeCallback([$this, 'onFooResponse']);
     $this->dealer->filter(function (Event $event) {
         return $event->is("/response/bar");
     })->subscribeCallback([$this, 'onBarResponse']);
     echo "Will ask router every 5 seconds\n";
     $this->loop->addPeriodicTimer(5, [$this, 'askRouter']);
 }
开发者ID:domraider,项目名称:rxnet,代码行数:14,代码来源:dealer.php

示例13: listen

 /**
  * @param int    $port
  * @param string $host
  */
 public function listen($port, $host)
 {
     $this->http->on('request', function (ReactRequest $request, ReactResponse $response) {
         return $this->onRequest($request, $response);
     });
     $this->logger->info("Phiremock http server listening on {$host}:{$port}");
     $this->socket->listen($port, $host);
     // Dispatch pending signals periodically
     if (function_exists('pcntl_signal_dispatch')) {
         $this->loop->addPeriodicTimer(0.5, function () {
             pcntl_signal_dispatch();
         });
     }
     $this->loop->run();
 }
开发者ID:mcustiel,项目名称:phiremock,代码行数:19,代码来源:ReactPhpServer.php

示例14: run

 /**
  * Start server
  *
  * @throws RuntimeException
  */
 public function run()
 {
     try {
         $this->loop->addPeriodicTimer($this->timePeriod, $this->getPeriodicTimerCallback());
         //listening of the ports
         foreach ($this->listen as $port) {
             $socket = new Server($this->loop);
             //initialize socket
             $socket->on('connection', function (Connection $conn) {
                 $this->conns->attach($conn);
                 $conn->on('data', function ($data, $conn) {
                     //$request insteadof React\Http\Request
                     list($request, $body) = (new RequestHeaderParser())->parseRequest($data);
                     $this->conns->attach($conn, new LongPooling\ConnectionInfo($request, $body));
                 });
                 $conn->on('end', function ($conn) {
                     $this->conns->detach($conn);
                 });
             });
             $socket->listen($port);
         }
         $this->loop->run();
     } catch (Exception $e) {
         throw new RuntimeException("Server Run Exception", 301, $e);
     }
 }
开发者ID:necromant2005,项目名称:tt-long-pooling,代码行数:31,代码来源:LongPooling.php

示例15: launch

 /**
  * @param bool $profile
  *
  * @throws \React\Socket\ConnectionException
  */
 public function launch($host, $port, $profile)
 {
     $this->logger->info('Starting web socket');
     $stack = new Builder();
     $server = new Server($this->loop);
     $server->listen($port, $host);
     if (true === $profile) {
         $memoryUsagePeriodicTimer = new PeriodicMemoryUsage($this->logger);
         $this->periodicRegistry->addPeriodic($memoryUsagePeriodicTimer);
     }
     /** @var PeriodicInterface $periodic */
     foreach ($this->periodicRegistry->getPeriodics() as $periodic) {
         $this->loop->addPeriodicTimer($periodic->getTimeout(), [$periodic, 'tick']);
         $this->logger->info(sprintf('Register periodic callback %s, executed each %s seconds', $periodic instanceof ProxyInterface ? get_parent_class($periodic) : get_class($periodic), $periodic->getTimeout()));
     }
     $allowedOrigins = array_merge(array('localhost', '127.0.0.1'), $this->originRegistry->getOrigins());
     $stack->push('Ratchet\\Server\\IoServer', $server, $this->loop)->push('Ratchet\\Http\\HttpServer');
     if ($this->originCheck) {
         $stack->push('Gos\\Bundle\\WebSocketBundle\\Server\\App\\Stack\\OriginCheck', $allowedOrigins, $this->eventDispatcher);
     }
     $stack->push('Ratchet\\WebSocket\\WsServer')->push('Gos\\Bundle\\WebSocketBundle\\Server\\App\\Stack\\WampConnectionPeriodicTimer', $this->loop)->push('Ratchet\\Session\\SessionProvider', $this->sessionHandler)->push('Ratchet\\Wamp\\WampServer');
     $app = $stack->resolve($this->wampApplication);
     /* Server Event Loop to add other services in the same loop. */
     $event = new ServerEvent($this->loop, $server);
     $this->eventDispatcher->dispatch(Events::SERVER_LAUNCHED, $event);
     $this->logger->info(sprintf('Launching %s on %s PID: %s', $this->getName(), $host . ':' . $port, getmypid()));
     $app->run();
 }
开发者ID:plfort,项目名称:WebSocketBundle,代码行数:33,代码来源:WebSocketServer.php


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