Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A PHP long running process that fires a command at a command bus at regular time intervals
#!/usr/bin/env php
<?php
declare(strict_types=1);
namespace CodeReviewsIo\Worker;
use CodeReviewsIo\Domain\Command\TickTime;
use Prooph\ServiceBus\CommandBus;
use React\EventLoop\Factory;
use Zend\ServiceManager\ServiceManager;
call_user_func(function () {
require_once __DIR__ . '/../vendor/autoload.php';
set_time_limit(0);
$servicesConfig = require __DIR__ . '/../config/all-configs-merged-together.php';
$loop = Factory::create();
$tickInterval = 15 * 60;
$loop->addPeriodicTimer(
$tickInterval,
function () use ($servicesConfig) {
/* @var $commandBus callable */
$commandBus = (new ServiceManager($servicesConfig))
->get(CommandBus::class);
$commandBus(TickTime::fromCurrentPointInTime());
// @TODO this is required, or connections will never be GC'd
gc_collect_cycles();
}
);
$loop->run();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment