zoukankan      html  css  js  c++  java
  • ThinkPHP5实现定时任务

    最近使用ThinkPHP5做了个项目,项目中需要定时任务的功能,感觉有必要分享下 
    TP5做定时任务使用到command.php的 
    步骤如下: 
    1.配置command.php文件,位于application/command.php 

    <?php
    namespace apphomecommand;
    use thinkconsoleCommand;
    use thinkconsoleInput;
    use thinkconsoleOutput;
    class Test extends Command
    {
        protected function configure()
        {
            $this->setName('test')->setDescription('Here is the remark ');
        }
        protected function execute(Input $input, Output $output)
        {
            $schedule = new Scheduletask();
                $schedule -> run();
            $output->writeln("TestCommand:");
        }
    }

    configure函数是在命令行中用list命令列出所有任务的时候回显示的出的提示,execute函数是说要执行的命令,在这里可以直接调用其他函数,完成例如统计等任务工作,然后用output输出到命令行 
    3.运行test命令 
    打开命令行,运行php think test命令test命令execute方法中运行的方法就会运行 
    4.在入口文件处,新建bat文件,内容如下 
    D: 
    cd D:phpStudyWWWOilTycoon 
    php think test 
    切换到D盘 
    切换到项目根目录处 
    运行test命令 
    5.把bat文件加入到服务器的定时任务中

  • 相关阅读:
    (摘)Zebra打印机异常处理
    (摘)Chart Y轴设置为百分比
    关于ZFS、GPT、4K、Geom Label的一些说明
    (转)ASP.NET性能优化之分布式Session
    (转)WebService的事务处理
    SqlSever分页查询,仅扫描一次表
    (转)对.net系统架构改造的一点经验和教训
    字典树
    Ajax
    Lunix 命令
  • 原文地址:https://www.cnblogs.com/whowhere/p/9681765.html
Copyright © 2011-2022 走看看