zoukankan      html  css  js  c++  java
  • Yii2 定时任务创建(Console 任务)

    Yii2有强大的定时任务执行功能(Console),在项目目录下的console目录,可在该目录新建执行任务的控制器

    我们先建一个TestController.php的控制器

    <?php
    namespace consolecontrollers;
     
    use yiiconsoleController;
     
    class TestController extends Controller
    {
        public function actionTest()
        {
            echo "test
    ";
        }
    }
    

      

    在yii根目录下,命令行执行

    yii test/test
    

      

    如果是class AaaBbbController function ActionAaaBbb

    yii aaa-bbb/aaa-bbb
    

      

    linux下,运行crontab -e

    上面的例子表示每晚的21:30执行上面的定时程序

    下面是定时任务设置的一些基本介绍

    基本格式 :
    *  *  *  *  *  command
    分 时 日 月 周 命令

    第1列表示分钟1~59 每分钟用*或者 */1表示
    第2列表示小时1~23(0表示0点)
    第3列表示日期1~31
    第4列表示月份1~12
    第5列标识号星期0~6(0表示星期天)
    第6列要运行的命令

    crontab文件的一些例子:

  • 相关阅读:
    选择排序
    散列冲突解决方案
    string stringbuffer StringBuilder
    java关键字
    Vector
    What is the difference between book depreciation and tax depreciation?
    Type of Asset Books in Oracle Fixed Assets
    questions
    Oracle Express 11g
    iot
  • 原文地址:https://www.cnblogs.com/cxscode/p/7875351.html
Copyright © 2011-2022 走看看