toflar/cronjob-supervisor
Run and cap background workers using only a minutely cronjob—no supervisord needed. Define commands with desired concurrency; the supervisor tracks running processes and prevents overspawning across minutes via ps/tasklist/flock providers, working on Linux and Windows.
Need to have a number of workers on some server but have no access to any daemon like supervisord or the likes but
can configure a minutely cronjob? This library might come in handy for you then.
composer require toflar/cronjob-supervisor
runner.php:<?php
require_once 'vendor/autoload.php';
use Symfony\Component\Process\Process;
use Toflar\CronjobSupervisor\BasicCommand;
use Toflar\CronjobSupervisor\Supervisor;
$supervisor = Supervisor::withDefaultProviders('/some/directory/you/want/to/store/your/state');
$supervisor
->withCommand(new BasicCommand('sleep 10', 2, function () {
return new Process(['sleep', '10']);
}))
->withCommand(new BasicCommand('sleep 29', 4, function () {
return new Process(['sleep', '29']);
}))
->supervise()
;
* * * * * /path/to/your/php/binary/php runner.php
That's it. The Supervisor will take care that even if your jobs are still running after a minute has passed, only
ever your maximum number of processes will be created.
For this to work, it uses multiple providers to check if processes are still running. Currently supported are:
ps -p <pid> [Linux]tasklist /FI PID eq <pid> [Windows]flock - [Linux, Windows]Which means it runs everywhere (flock as the fallback).
How can I help you explore Laravel packages today?