zoukankan      html  css  js  c++  java
  • Yii2安装任务调度扩展

    一、安装扩展

      在安装之前添加仓库到composer.json文件中

      "repositories": [{"type": "vcs", "url": "https://git.oschina.net/zjq528/yii2-cron.git"}],

     在项目的根目录下运行composer命令
     composer require webjson/yii2-cron

    二、使用

    <?php
    namespace consolecontrollers;
    
    use webjsoncronScheduleController;
    
    class TestController extends ScheduleController {
    
      public function actionRun()
      {
        // 每小时执行一次 hello/index 命令
        $this->command('hello/index')->everyHour();
      }
    }
    

    ScheduleController是一个抽象类,里面有一个抽象方法 actionRun 这里就放要定时执行的任务

    最后在crontab里面添加

    * * * * * php yii test/run
  • 相关阅读:
    链表实现
    @Aspect
    mybatis plus
    using
    50道题
    梦想,青春,时间
    存储过程!!!
    事务,视图,索引
    高级查询--嵌套和相关,两套分页!!!
    学习笔记
  • 原文地址:https://www.cnblogs.com/zhangjianqiang/p/7054919.html
Copyright © 2011-2022 走看看