anxu / crontab
crontab for yii2 framework
v0.1
2017-12-13 10:07 UTC
Requires
- php: >=5.4.0
- mtdowling/cron-expression: ^1.0
- yiisoft/yii2: ~2.0.5
Requires (Dev)
- codeception/base: ^2.3
- yiisoft/yii2-faker: ~2.0.0
This package is auto-updated.
Last update: 2025-01-11 19:36:49 UTC
README
Yii2 的插件,管理所有后台定时任务,不用修改 crontab
注意
无法在window系统服务器中运行
用法
通过 composer
安装
composer require anxu/crontab:"*"
Yii2 console 脚本,示例如下:
namespace app\commands; use yii\console\Controller; use anxu\Crontab\Crontab; class DemoController extends Controller { public function actionIndex() { // 从数据库获取执行的任务 $jobs=[ [ 'name'=>'1', 'schedule'=>'* * * * *', 'command'=>'date', 'output'=>'log/log.log' ],[ 'name'=>'2', 'schedule'=>'* * * * *', 'command'=>'echo "test2"', 'output'=>'log/log.log' ] ]; $a = new Crontab(); $a->add($jobs); $a->run(); } }
将上面的脚本加入crontab
中,如下所示:
* * * * * /path/to/project/yii demo/index 1>> /dev/null 2>&1
最后,启动crontab
"Y-m-d H:i:s" 格式,后面的 秒s 会被忽略;