本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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);
}
示例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'));
}
示例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']);
}
示例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']);
}
}
示例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();
});
}
示例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));
}
示例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
});
}
示例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);
}
}
示例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']);
}
示例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();
}
示例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);
}
}
示例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();
}