zoukankan      html  css  js  c++  java
  • laravel5.2总结--任务调度

    你可以通过 command() 来调用 artisan 命令, call 来调用方法或函数, 或者 terminal() 来执行单行命令脚本:
     
    1.在app/Console/Commands文件夹下生成php文件
    php artisan make:console Refresh
     
    修改名字 protected $signature = 'refresh';
    修改描述 protected $description = '定时任务';
    写入操作方法
    public function handle()
    {
    //写你要运行的方法
    }
     
    2.在app/Console文件夹下的Kernel.php 文件中注册
    protected $commands = [
    CommandsInspire::class,
    CommandsRefreshToken::class,
    ];
     
    protected function schedule(Schedule $schedule)
    {
    $schedule->command('inspire')
    ->hourly();
    $schedule->command('refresh')
    ->everyMinute();
    }
     
    3、一个需要加入到服务器的 Cron 项目,创建cron.txt文件,里面写的内容(/path/to/artisan替换成你自己的地址)
     
    * * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
     
     
    4、终端中用命令开启任务
     
    在终端中项目目录下(Linux 环境)
     
    告诉crontab 文件名: 
    crontab cron.txt
     
    开始定时任务
    crontab -l
     
    或许之后你要结束任务 
    crontab -r
  • 相关阅读:
    【转】 Linux进程间通信
    Django中的Templates
    Django中的应用
    url的使用
    Django框架的使用
    Django的安装
    文件上传
    flask中的request和response
    模板
    静态文件处理
  • 原文地址:https://www.cnblogs.com/redirect/p/7457034.html
Copyright © 2011-2022 走看看