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 * * * *)
| Option | Type | Default | Description | 
|---|---|---|---|
| name | string | not set | Optional. The name associated with the worker process. | 
| schedule | int | "1 minute" | Optional. Schedule in one of the formats described above. | 
| jitter | int | 0 | Optional. Jitter in seconds that adds a random time offset to the schedule. | 
| user | int | not set | Optional. Unix user of process. Current user by default. | 
| group | int | not set | Optional. Unix group of process. Current group by default. | 
| onStart | Closure | not set | Optional. A callback function executed when the worker starts. |