tasque/event-loop

v0.1.2 2023-11-08 18:08 UTC

This package is auto-updated.

Last update: 2024-04-06 07:44:08 UTC


README

Build Status

Run a ReactPHP event loop within a conventional PHP application using Tasque.

Why?

To allow periodic background tasks, such as sending keep-alive or heartbeat messages, to be performed in a traditional PHP environment where there would otherwise be no event loop.

Usage

Install this package with Composer:

$ composer install tasque/event-loop

Configure Nytris platform:

nytris.config.php

<?php

declare(strict_types=1);

use Nytris\Boot\BootConfig;
use Nytris\Boot\PlatformConfig;
use Tasque\EventLoop\TasqueEventLoopPackage;
use Tasque\TasquePackage;

$bootConfig = new BootConfig(new PlatformConfig(__DIR__ . '/var/cache/nytris/'));

$bootConfig->installPackage(new TasquePackage());
$bootConfig->installPackage(new TasqueEventLoopPackage());

return $bootConfig;

Setting a timer

Just use a standard ReactPHP timer, as long as the package is configured in nytris.config.php as above.

index.php

<?php

declare(strict_types=1);

use React\EventLoop\Loop;

require_once __DIR__ . '/vendor/autoload.php';

Loop::addPeriodicTimer(1, function () {
    print 'Timer elapsed' . PHP_EOL;
});

See also