overnaive / think-swoole-crontab
基于 think-swoole 的 crontab 组件。
v0.1.0
2020-12-17 15:22 UTC
Requires
- php: ^7.1
- nesbot/carbon: ^2.0
- topthink/think-swoole: ^3.0
README
基于 think-swoole 的 crontab 组件。
声明
核心逻辑来自 Hyperf 的 hyperf/crontab 组件。非常感谢 Hyperf 为大家提供了如此优秀的组件。
本组件尝试使其在 ThinkPHP 中运行(需结合 think-swoole 组件)。
目前仍处于初步可用阶段,后续会逐渐完善。
需求
- PHP >= 7.1
- Composer
安装
composer require overnaive/think-swoole-crontab
文档
用法
- 在
event.php
中为swoole.init
事件添加监听类。
return [
...
'listem' => [
...
'swoole.init' => [
...
\ThinkSwooleCrontab\Process\CrontabDispatcherProcess::class,
...
],
...
],
...
];
- 在配置文件
crontab.php
中添加\ThinkSwooleCrontab\Crontab
实例。
return [
'crontab' => [
(new \ThinkSwooleCrontab\Crontab())->setName('test-1')
->setRule('* * * * * *')
->setCallback([Test::class, 'run'])
->setMemo('just a test crontab'),
(new \ThinkSwooleCrontab\Crontab())->setName('test-2')
->setRule('* * * * * *')
->setCallback([Test::class, 'run'])
->setMemo('just another test crontab'),
],
];
许可证
MIT