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.
- Defining schedules using cron syntax.
- Defining schedules using relative date format as supported by \DateInterval.
$ composer require phpstreamserver/core phpstreamserver/scheduler
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());
$ php server.php start