Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ReactPHP Drupal Tasks
<?php declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
function run_command(string $command): void {
$loop = React\EventLoop\Factory::create();
$process = new React\ChildProcess\Process($command);
$process->start($loop);
$process->on('exit', function ($exitCode) use ($command) {
// Trigger alerts that the command finished.
});
$process->stdout->on('data', function ($chunk) {
// Optinally log the output.
});
$process->stdout->on('error', function (Exception $e) use ($command) {
// Log an error.
});
$process->stderr->on('data', function ($chunk) use ($command) {
if (!empty(trim($chunk))) {
// Log output from stderr
}
});
$process->stderr->on('error', function (Exception $e) use ($command) {
// Log an error.
});
$loop->run();
}
$loop = React\EventLoop\Factory::create();
// Run cron every twenty minutes.
$loop->addPeriodicTimer(1200, function () {
run_command('drush cron');
});
// Every thirty seconds, process jobs from queue1
$loop->addPeriodicTimer(30, function () {
run_command(sprintf('drush advancedqueue:queue:process queue1'));
});
// Every two minutes, process jobs from queue2
$loop->addPeriodicTimer(120, function () {
run_command(sprintf('drush advancedqueue:queue:process queue2'));
});
$loop->run();
<?php
$autoloader = require __DIR__ . '/../vendor/autoload.php';
$request = Symfony\Component\HttpFoundation\Request::createFromGlobals();
$request->attributes->set(
Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT,
new Symfony\Component\Routing\Route('<none>')
);
$request->attributes->set(
Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_NAME,
'<none>'
);
$kernel = new Drupal\Core\DrupalKernel('prod', $autoloader);
$kernel::bootEnvironment();
$kernel->setSitePath('sites/default');
Drupal\Core\Site\Settings::initialize($kernel->getAppRoot(), $kernel->getSitePath(), $autoloader);
$kernel->boot();
$kernel->preHandle($request);
$loop = React\EventLoop\Factory::create();
$loop->addPeriodicTimer(10, function () {
$cron = \Drupal::service('cron');
$cron->run();
});
$loop->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.