phpstreamserver / scheduler
Scheduler plugin for PHPStreamServer
v0.3.0
2024-12-06 17:26 UTC
Requires
- php: >=8.2
- ext-pcntl: *
- ext-posix: *
- amphp/amp: ^3.0.2
- dragonmantank/cron-expression: ^3.4
- phpstreamserver/core: ^0.3
- revolt/event-loop: ^1.0.6
README
Scheduler Plugin for PHPStreamServer
The Scheduler Plugin for PHPStreamServer extends the core functionality by providing a scheduling capability, allowing you to run programs or tasks at specific intervals, much like a traditional cron job.
Features
- Defining schedules using cron syntax.
- Defining schedules using relative date format as supported by \DateInterval.
Install
$ composer require phpstreamserver/core phpstreamserver/scheduler
Configure
Here is an example of a simple server configuration with scheduler.
// server.php use PHPStreamServer\Core\Server; use PHPStreamServer\Plugin\Scheduler\PeriodicProcess; use PHPStreamServer\Plugin\Scheduler\SchedulerPlugin; $server = new Server(); $server->addPlugin( new SchedulerPlugin(), ); $server->addWorker( new PeriodicProcess( name: 'Scheduled process', schedule: '*/1 * * * *', onStart: function (PeriodicProcess $worker): void { // runs every 1 minute }, ), ); exit($server->run());
Run
$ php server.php start