Laravel 定時任務

一 、建立Command文件

php artisan make:console RefreshToken

 

建立app/Console/Commands 下建立RefreshToken.phpphp

取一個名字

protected $signature = 'refreshToken';

 

添加描述

protected $description = 'Refresh Api Token';

 

 在 handle() 方法中實現功能

public function handle()
{
    Log::info('Token Refreshed');
}

 

2、在Kernel.php 文件中註冊

    //Commands\Inspire::class,
         Commands\RefreshToken::class,
    ];
protected function schedule(Schedule $schedule)
    {
         $schedule->command('refreshToken')
                  ->everyMinute();
    }

 

3、新建cron.txt文件

文件內容:app

* * * * * php /home/w/code/BTLIS/artisan schedule:run >> /dev/null 2>&1

 

4、用命令開啓任務

在終端中項目目錄下(Linux 環境)
告訴crontab 文件名: spa

crontab cron.txt


開始定時任務code

crontab -l

 

或許以後你要結束任務 blog

crontab -r
相關文章
相關標籤/搜索