Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Last active April 14, 2017 17:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Ocramius/530af20b1db06519967fa3100dc938fb to your computer and use it in GitHub Desktop.
Save Ocramius/530af20b1db06519967fa3100dc938fb to your computer and use it in GitHub Desktop.
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