laravel创建定时任务
官方文档给出的教程已经很详细了,这里给出一些补充帮助大家理解。
英文文档:https://laravel.com/docs/5.2/scheduling
中文文档:https://laravel-china.org/docs/5.2/scheduling
Starting The Scheduler
这里文档说的很简单,就是让你在服务器的crontab加入一条命令。
* * * * * php /path/to/artisan schedule:run >> /dev/null >&
关于crontab可以参考这篇文章:http://www.cnblogs.com/xxoome/p/6091459.html
这条命令什么意思呢?按照crontab配置文件格式的解释

红框内都是shell命令。
##如果配有配置php的全局环境变量,这里需要指定php的绝对路径。
php:/usr/local/php/bin/php
##就是你项目根目录下的artisan文件的绝对路径
artisan:/home/prj-test/test/artisan
例如:
* * * * * /usr/local/php/bin/php /home/prj-test/test/artisan schedule:run >> /dev/null >&
========================== 我是分割线 ===========================
1、创建artisan命令行
文档地址:https://laravel-china.org/docs/5.2/artisan
php artisan make:console TestConsole
<?php namespace App\Console\Commands; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log; class TestConsole extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'testconsole'; /**
* The console command description.
*
* @var string
*/
protected $description = '这是一个测试artisan的描述'; /**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
} /**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
Log::info('这是我写的log');
}
}
2、编写Kernel
<?php namespace App\Console; use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Log; class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
// Commands\Inspire::class,
Commands\TestConsole::class
]; /**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
Log::info('zddddd');
//调用artisan
$schedule->command('testconsole')->everyMinute();
}
}
有问题欢迎留言交流。
技术交流群:576269252
--------------------------------------
声明: 原创文章,未经允许,禁止转载!
--------------------------------------
laravel创建定时任务的更多相关文章
- laravel的定时任务
首先在laravel项目命令创建: php artisan make:command TestCommand 会在App\Console\Commands文件下看到TestCommand.php文件, ...
- 使用Quartz创建定时任务
项目开发中经常需要定时循环执行某些任务 比如定时发送报表,定时发送邮件,亦或者定时清理缓存,定时更新数据等等 有些时候可以简单地利用Windows Server的计划任务执行程序 Linux也有相应的 ...
- Yii通过控制台命令创建定时任务
假设Yii项目路径为 /home/apps/ 1. 创建文件 /home/apps/protected/commands/crons.php <?php $yii = '/home/apps/f ...
- JAVAEE——BOS物流项目13:Quartz概述、创建定时任务、使用JavaMail发送邮件、HighCharts概述、实现区域分区分布图
1 学习计划 1.Quartz概述 n Quartz介绍和下载 n 入门案例 n Quartz执行流程 n cron表达式 2.在BOS项目中使用Quartz创建定时任务 3.在BOS项目中使用Jav ...
- 禁用了传说中的PHP危险函数之后,Laravel的定时任务不能执行了?
虽然已是 2018 年,但网上依然流传着一些「高危 PHP 函数,请一定要禁用!」的标题党文章(搜索关键字:一些需要禁用的PHP危险函数). 这些文章的内容简单直接,给出 php.ini 的 disa ...
- windows创建定时任务执行python脚本
一.创建定时任务 \ [程序或脚本]文本框中填的是Python编译器的名称,一般就是python.exe, [起始于]文本框中填的是Python编译器的目录,上图中假设你的Python编译器的完整路径 ...
- Springboot定时任务原理及如何动态创建定时任务
一.前言 上周工作遇到了一个需求,同步多个省份销号数据,解绑微信粉丝.分省定时将销号数据放到SFTP服务器上,我需要开发定时任务去解析文件.因为是多省份,服务器.文件名规则.数据规则都不一定,所以要做 ...
- linux创建定时任务,定时执行sql
终于弄清楚一个问题了.linux创建定时任务,定时执行sql,其中分为两个case. case-1 sql语句较少,因此直接在 shell脚本中 写sql语句.如下: [oracle@Oracle11 ...
- Spring Boot中使用@Scheduled创建定时任务
我们在编写Spring Boot应用中经常会遇到这样的场景,比如:我需要定时地发送一些短信.邮件之类的操作,也可能会定时地检查和监控一些标志.参数等. 创建定时任务 在Spring Boot中编写定时 ...
随机推荐
- 里氏替换原则LSP(继承规范)
继承的优点: 1.代码共享,减少创建类的工作量,每个子类都拥有父类的方法和属性. 2.提高代码的重用性. 3.子类可以形似父类,但又异于父类. 4.提高代码的可扩展性,实现父类的方法就可以“为所欲为” ...
- HtmlParser应用
HtmlParser应用,使用Filter从爬取到的网页中获取需要的内容 { String url = "http://wenku.baidu.com/search?word=htmlpar ...
- 关于JdbcTemplate的queryForList返回值
通过spring的jdbctemplate返回的list其实封装的是需要通过如下方法得到里面的内容的 public void getAllUsers() { List allUsers = new A ...
- tag标签记录
看到项目代码中有一个自定义的tag标签,想起以前自己写过的标签,竟然忘记的差不多了,手一痒,自己写个简单的tag标签,回顾一下历史知识 首先建一个servlet工程,然后写个index.jsp,项目跑 ...
- continue与break
1.continue语句,1至20内奇数累加和 #include<iostream> using namespace std; void main(){ int i=0; int sum= ...
- YC(Y Combinator)斯坦福大学《如何创业》课程要点记录(粗糙)
20节课程,每节都是干货满满,时常听说理论无用,但是好的理论,绝对能帮助你少走一些弯路. YC简介: Y Combinator成立于2005年,是美国著名创业孵化器,Y Combinator扶持初创企 ...
- redis 学习笔记——数据同步、事务
redis主从同步 redis支持简单易用的主从复制(master-slave replication)功能,该功能也是redis高可用性实现的基础. redis复制原理 re ...
- Url Rewrite IIS 配置
在configuration节点下 <system.webServer> <rewrite> <rules> <rule name="rD" ...
- SELinux开启和关闭
1.查看SELinux状态 /usr/sbin/sestatus -v 2.关闭SELinux (1)临时关闭(不用重启机器): setenforce 0 #设置SELinux成为permissive ...
- JTree事件
package com.wf; import javax.swing.*; import javax.swing.event.TreeSelectionEvent; import javax.swin ...