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. python之浅谈数据类型

    什么是数据类型 ​ 数据类型指的就是变量值的不同类型,姓名可能是一种数据类型.年龄可能是一种数据类型.爱好可能又是另一种数据类型,至于是什么数据类型我们将在下一章详细说明. 如何对数据分类 变量的是用 ...

  2. 51单片机入门1--与C语言的交接

    我们即将进入51单片机的编程学习,咱们今天就来讲解一下单片机中的C语言(你可以称作C51) 在说编程之前,要先说一些别的东西: 二进制,八进制,十六进制 二进制中只有数字0和1,在二进制中1+1为10 ...

  3. 前端动画必知必会:React 和 Vue 都在用的 FLIP 思想实战

    前言 在 Vue 的官网中的过渡动画章节中,可以看到一个很酷炫的动画效果 乍一看,让我们手写出这个逻辑应该是非常复杂的,先看看本文最后要实现的效果吧,和这个案例是非常类似的. 预览 分析需求 拿到了这 ...

  4. 精简CSS代码,提高代码的可读性和加载速度

    前言 提高网站整体加载速度的一个重要手段就是提高代码文件的网络传输速度.之前提到过,所有的代码文件都应该是经过压缩了的,这可提高网络传输速度,提高性能.除了压缩代码之外,精简代码也是一种减小代码文件大 ...

  5. 无题 II 二分图最大匹配

    题目描述 这是一个简单的游戏,在一个n*n的矩阵中,找n个数使得这n个数都在不同的行和列里并且要求这n个数中的最大值和最小值的差值最小. Input 输入一个整数T表示T组数据. 对于每组数据第一行输 ...

  6. 阿里云上安装启动nginx 以及在个人电脑上通过公网ip访问遇到的问题

    1.安装依赖包 //一键安装上面四个依赖 yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel 2.下载并解压安装包 ...

  7. 006.Nginx访问控制

    一 Nginx连接限制 1.1 HTTP协议的连接与请求 HTTP是建立在TCP, 一次HTTP请求需要先建立TCP三次握手(称为TCP连接),在连接的基础上再进行HTTP请求. HTTP请求建立在一 ...

  8. redis(十九):Redis 架构模式,特点

    单机版 特点:简单 问题: 1.内存容量有限 2.处理能力有限 3.无法高可用. 主从复制 Redis 的复制(replication)功能允许用户根据一个 Redis 服务器来创建任意多个该服务器的 ...

  9. IOS10 window.navigator.geolocation.getCurrentPosition 无法定位问题

    在iOS 10中,苹果对webkit定位权限进行了修改,所有定位请求的页面必须是https协议的. 如果是非https网页,在http协议下通过HTML5原生定位接口会返回错误,也就是无法正常定位到用 ...

  10. INS-40718 和 INS - 30516

    RAC  安装的时候报错, INS-40718 这个是自己填写的  scan name 和 /etc/hosts  里定义的不一致  可以cat   /etc/hosts   看一下 INS - 30 ...