readdle / scheduler
此包已被放弃,不再维护。未建议替代包。
Scheduler 是一个类似 cron 的 php 环境,用于 docker 容器
1.2
2016-10-19 12:32 UTC
This package is not auto-updated.
Last update: 2020-02-07 16:46:13 UTC
README
通用调度器项目
- 在 docker 容器中运行测试
docker-compose up
示例用法
<?php include "./vendor/autoload.php"; // Example of scheduled script class SomeScript { protected $name; public function __construct(string $name) { $this->name = $name; } public function __invoke() { echo time() . " - {$this->name}" . PHP_EOL; } } // Mock of persistent storage. In production we reccomend to use redis storage class Storage { protected $keyValue = []; public function set(string $key, int $value) { $this->keyValue[$key] = $value; } public function get(string $key) { return array_key_exists($key, $this->keyValue) ? $this->keyValue[$key] : null; } } $storage = new Storage(); // Create scheduler object $scheduler = new \Readdle\Scheduler\Scheduler( new \Readdle\Scheduler\PersistentStorage( 'test', [$storage, 'set'], [$storage, 'get'] ) ); // Register your scripts $scheduler->register(10, new SomeScript('10 second')); $scheduler->register(5, new SomeScript('5 second')); $scheduler->register(20, new SomeScript('20 second')); $scheduler->register(7, new SomeScript('7 second')); $scheduler->register(27, new SomeScript('27 second')); // Start scheduler loop $scheduler->loop();