Fork me on GitHub

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 = [
Commands\Inspire::class,
Commands\RefreshToken::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
posted @ 2017-08-31 10:38  archer-wong  阅读(330)  评论(0编辑  收藏  举报