1、创建命令

php artisan make:command command_name --command=artisan_command_name

# Explanation:
# command_name: 生成的文件名
# artisan_command_name: php artisan 命令调度时的命令名称
# 结果: 在 /app/Console/Commands/ 下生成名为 command_name.php 的文件 # Example:
# php artisan make:command LeaderMail --command=LeaderMail
# 生成的文件名:LeaderMail
# 调度时的命令名称:LeaderMail

2、测试刚才生成的命令是否OK

php artisan LeaderMail

# Explanation:
# 没有返回则表示成功。
# 因为 /app/Console/Commands/LeaderMail.php 的 handle 方法中没有写内容。写了就会有返回。

3、编辑生成的文件 /app/Console/Commands/LeaderMail.php 的 handle 方法

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class LeaderMail extends Command
{
/**
* The name and signature of the console command.
* 用来描述命令的名字与参数
* @var string
*/
protected $signature = 'LeaderMail'; /**
* The console command description.
* 存储命令描述
* @var string
*/
protected $description = 'Command description'; /**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
} /**
* Execute the console command.
* 执行命令进行的操作
* @return mixed
*/
public function handle()
{
// 这里是任务的具体处理
}
}

4、编辑 App\Console\Kernel.php 文件,添加调度

# 先到 /app/Console/Kernel.php 中 $commands 数组中进行注册。
# 然后在 /app/Console/Kernel.php 的 schedule 方法中定义调度任务。
<?php

namespace App\Console;

use App\Console\Commands\LeaderMail;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
* 你的应用程序提供的Artisan命令。
* @var array
*/
protected $commands = [
LeaderMail::class
]; /**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly(); // 每分钟执行一次获取领导信箱
// command() 调度时的命令名称
// everyFiveMinutes() 调度规则
// appendOutputTo() 调度命令进行操作的返回结果记录文件
$schedule->command('LeaderMail')->everyFiveMinutes()->appendOutputTo(base_path('storage/crontab/log.log'));
} /**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__ . '/Commands'); require base_path('routes/console.php');
}
}

5、编辑机器的定时任务 crontab

# 复习
# crontab -l # 查看
# crontab -e # 编辑
# crontab -r # 删除所有 # 开始操作
crontab -e
# 然后添加以下语句
* * * * * path-to-your-php/bin/php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1 # Explanation:
# path-to-your-php/bin/php 是你的PHP的绝对路径,通过 which php 可以得到;
# path-to-your-project/artisan 是你项目中Laravel框架中根目录下的 artisan 的绝对路径;

6、如果想单独写出来也可以

* * * * * path-to-your-php/bin/php /path-to-your-project/artisan LeaderMail >> /dev/null 2>&1

Laravel 定时任务调度 的 Artisan 命令调度的更多相关文章

  1. 【Laravel】 常用的artisan命令【原创】

    全局篇   查看artisan命令 php artisan php artisan list   查看某个帮助命令 php artisan help make:model   查看laravel版本 ...

  2. Laravel 的 make:auth Artisan 命令到底生成了哪些文件?

    众所周知,在 Laravel 中执行 $ php artisan make:auth $ php artisan migrate 命令后,我们就能拥有一个完整的登录.注册认证系统,这为开发带来极大的便 ...

  3. 【Laravel】 常用的artisan命令

    全局篇 查看artisan命令php artisanphp artisan list 查看某个帮助命令php artisan help make:model 查看laravel版本php artisa ...

  4. laravel开发之-php artisan命令

    php artisan :所有的命令列表 php artisan make:controller 文件夹名称/控制器名称 :创建控制器的命令以及控制器放置的文件夹 php artisan make:m ...

  5. laravel 5.0 artisan 命令列表(中文简体)

    #php artisan list Laravel Framework version Usage: [options] command [arguments] Options(选项): --help ...

  6. laravel常用的artisan命令

    转载来源链接: https://blog.csdn.net/jiandanokok/article/details/72897682 全局篇 查看artisan命令 php artisan php a ...

  7. 记录对定时任务调度器的小小改进 - API调度计划

    之前记录过一篇 [开源一个定时任务调度器 webscheduler],这是一个看似简单的小工具,昨天部署到服务器上开始试用下,听听反馈. 项目经理看过后,立马反馈说这个使用 Cron表达式 的计划太难 ...

  8. 【Laravel】 安装及常用的artisan命令

    composer Laravel 安装 cmd composer create-project laravel/laravel Laravel5 之后自动创建 常用的artisan命令 全局篇 查看a ...

  9. laravel中一些非常常用的php artisan命令

    php artisan 命令在开发laravel项目中非常常用,下面是一些总结 composer config -g repo.packagist composer https://mirrors.a ...

随机推荐

  1. JavaScript图形实例:递归生成树

    观察自然界中树的分叉,一根主干生长出两个侧干,每个侧干又长出两个侧干,以此类推,便生长出疏密有致的结构.这样的生长结构,使用递归算法可以模拟出来. 例如,分叉的侧干按45°的偏转角度进行生长的递归示意 ...

  2. Python3-在windows快速运行一个简单的本地 HTTP 服务器

    1.打开控制台2.python -m http.server

  3. 使用TransferLearning实现环视图像的角点检测——Tensorflow+MobileNetv2_SSD

    环境说明 依赖环境安装eIQ官方指南: name: eiq_auto channels: - conda-forge - defaults dependencies: - numpy=1.18.1=p ...

  4. 关于SQL SERVER 的日期格式化

    --日期格式化Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM Select CONVERT(varchar(100), G ...

  5. WIN10有线网络反复断开解决方法

    最近家里台式机碰到一个奇怪的问题,开机之后有线网络就时断时续,右下角网络图标不停在小地球与小电脑之间切换.网上大概搜索了一下,貌似碰到这种问题的朋友不在少数,但大部分朋友碰到的都是无线网络居多.这里把 ...

  6. 5年前端经验小伙伴教你纯css3实现饼状图

    有一些网页中,有时候会碰到饼状图的需求,比如统计图表,进度指示器,定时器等,实现方式也是各种各样,现在也有不少现成的js库,可以直接拿来使用,方便很多.这里笔者为大家演示一种纯css实现饼状图效果的方 ...

  7. 如何写出高性能的CSS3动画

    小伙伴们在写CSS3动画时,会发现在手机上很多时候会感到卡顿,然后Google到的解决方案大多是开启GPU加速transform: translate3d(0,0,0); 可解决,但是为什么开启GPU ...

  8. 如何科学地完成一场 AR 发布会?全在这份超细节活动策划 Xmind 里了

    你们在哪个酒店搭的景? 5 月 28 日,网易智慧企业完成了一场实景人物拍摄 + 虚拟舞台渲染的 AR 线上见面会.非常有趣的是,在直播过程中,不止一位观众问我们,“你们是在哪个酒店搭的景?”.看来我 ...

  9. 开发者必备——API设计问题

    本文主要探讨RPC和RESTFul两种API风格的特点以及在开发中应该如何进行技术选型,同时截取了网上社区,文章一部分关于API设计的想法和观点供读者参考,取舍. 1,背景简述 API学名:应用程序接 ...

  10. day20 函数收尾+面向过程+模块

    目录 一.算法(二分法) 二.面向过程与函数式 1 编程范式/思想 2 面向过程 3 函数式 3.1 匿名函数与lambda 三.模块 1 什么是模块 2 为何要有模块 3 怎么用模块 3.1第一次导 ...