- 配置console的Kernel
protected $commands = [
Commands\DoSomething::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('aaa:bbbbb')-> everyMinute(); //每分鐘執(zhí)行一次
}
- 新建command腳本
新建目錄App\Console\Commands
在Commands目錄下新建DoSomething類
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
/**
* 處理JIRA的project數(shù)據(jù)
*/
class DoSomething extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'aaa:bbbbb'; //執(zhí)行腳本的命令別名
/**
* The console command description.
*
* @var string
*/
protected $description = 'test schedule';
function __construct()
{
parent::__construct();
}
public function handle()
{
// 腳本的業(yè)務(wù)邏輯在這里寫即可
}
}
3. 執(zhí)行命令
a. 在命令行執(zhí)行php artisan schedule:run 將在1分鐘后執(zhí)行腳本
b. 在命令行執(zhí)行php artisan aaa:bbbbb將立刻執(zhí)行腳本
3. 在crontab里添加定時任務(wù)執(zhí)行php artisan schedule:run 即可定時執(zhí)行腳本
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。