envoylope/event-loop

v0.1.0 2024-05-06 22:54 UTC

This package is auto-updated.

Last update: 2024-12-07 00:09:11 UTC


README

Build Status

Transmits AMQP heartbeats for Envoylope using a ReactPHP EventLoop.

Usage

Install with Composer:

$ composer require envoylope/event-loop

(Optionally) install Tasque and Tasque EventLoop

If you are running a traditional PHP application, a ReactPHP EventLoop may regularly be blocked by synchronous logic/IO. This can be mitigated somewhat by Tasque EventLoop, which implements green threads for PHP.

See the respective usage instructions linked above for configuring the Tasque/EventLoop Nytris packages.

Configuring platform boot config

Once the PHP AMQP-Compat Nytris package is configured, this scheduler will be used:

nytris.config.php

<?php

declare(strict_types=1);

use Asmblah\PhpAmqpCompat\AmqpCompatPackage;
use Asmblah\PhpCodeShift\Cache\Layer\FilesystemCacheLayerFactory;
use Asmblah\PhpCodeShift\ShiftPackage;
use Envoylope\EventLoop\EventLoopSchedulerFactory;
use Nytris\Boot\BootConfig;
use Nytris\Boot\PlatformConfig;
use Tasque\Core\Scheduler\ContextSwitch\TimeSliceStrategy;
use Tasque\EventLoop\TasqueEventLoopPackage;
use Tasque\TasquePackage;

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

$bootConfig->installPackage(new AmqpCompatPackage(
    // Install the scheduler.
    schedulerFactory: new EventLoopSchedulerFactory()
));
$bootConfig->installPackage(new ShiftPackage(
    cacheLayerFactory: new FilesystemCacheLayerFactory(),
    relativeSourcePaths: ['src', 'vendor']
));
$bootConfig->installPackage(new TasquePackage(
    new TimeSliceStrategy(timeSliceCheckIntervalTocks: 100)
));
$bootConfig->installPackage(new TasqueEventLoopPackage());

return $bootConfig;