Skip to main content

Scheduler Plugin

Cron-like scheduler for executing tasks at specified intervals.

Installation

$ composer require phpstreamserver/scheduler

Example of Usage

server.php
use PHPStreamServer\Core\Server;
use PHPStreamServer\Plugin\Scheduler\SchedulerPlugin;
use PHPStreamServer\Plugin\Scheduler\Worker\PeriodicProcess;

$server = new Server();

$server->addPlugin(
new SchedulerPlugin(),
);

$server->addWorker(
new PeriodicProcess(
name: 'Periodic process',
schedule: '*/1 * * * *',
onStart: function (PeriodicProcess $worker): void {
// process
},
),
);

exit($server->run());

Plugin Configuration

🧩 SchedulerPlugin

Plugin class: SchedulerPlugin
This plugin does not have any specific configurable options.

Worker Configuration

⚙️ PeriodicProcess

Worker class: PeriodicProcess
This worker type is designed to execute tasks periodically.
The schedule option can be specified in one of the following formats:

  • Number of seconds (e.g., 60)
  • An ISO8601 datetime format (e.g., 2025-01-01 00:00:00)
  • An ISO8601 duration format (e.g., PT1M)
  • A relative date format (e.g., 1 minute)
  • A cron expression (e.g., */1 * * * *)
OptionTypeDefaultDescription
namestringnot setOptional. The name associated with the worker process.
scheduleint"1 minute"Optional. Schedule in one of the formats described above.
jitterint0Optional. Jitter in seconds that adds a random time offset to the schedule.
userintnot setOptional. Unix user of process. Current user by default.
groupintnot setOptional. Unix group of process. Current group by default.
onStartClosurenot setOptional. A callback function executed when the worker starts.