phpstreamserver/scheduler

Scheduler plugin for PHPStreamServer

v0.3.0 2024-12-06 17:26 UTC

This package is auto-updated.

Last update: 2024-12-06 17:57:02 UTC


README

Scheduler Plugin for PHPStreamServer

PHP >=8.2 Version Downloads

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