tp5定时任务
第一步:
a.App/模块/ 下创建command文件夹
b.我这边是创建在crontab模块里面,在command文件夹下创建一个Task.php文件(具体名字自己根据需求定)

c.复制下面的代码到Task.php
<?php
namespace app\crontab\command; use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\Db;
class Task extends Command
{
protected function configure()
{
$this->setName('task')
->setDescription('定时计划测试:每分钟插入一条数据');
} protected function execute(Input $input, Output $output)
{
// 输出到日志文件
$output->writeln("TestCommand:");
// 定时器需要执行的内容
$data = [
'name'=>'zxm22',
'addr'=>'上海'
];
db('blog')->insert($data);
$output->writeln("end....");
} }
第二步:在APP/command.php里面加上

第三步:在linux下设置crontab定时计划任务(我的项目文件放在/var/www/mytp5)即可
crontab -l //计划任务列表
crontab -e //编辑新增
crontab -r //删除

可参照:(查看php执行路径 whereis php)
1、配置command.php文件,目录在application/command.php 2、建立命令类文件,新建application/index/command/Test.php <?php
namespace app\index\command; use think\console\Command;
use think\console\Input;
use think\console\Output; class Test extends Command
{
protected function configure()
{
$this->setName('test')->setDescription('Here is the remark ');
} protected function execute(Input $input, Output $output)
{
$output->writeln("TestCommand:");
}
}
3、命令行下运行php think test ,将输出 TestCommand:,说明命令行已经成功 4、在linux系统配置crontab定时任务,一般目录在下图 4、根据自己的用户角色,编辑文件,如我是root用户,打开root文件,配置contab */1 * * * * cd /项目路径 && /php路径/php think test >> tmp/test.log 2>&1 这句话的意思是没一分钟执行一遍 test/index,日志存储在项目目录的 tmp/test.log文件里 根据上面的步骤就可以把定时任务跑起来了,很简单吧!!!
tp5定时任务的更多相关文章
- TP5 用cron实现linux定时任务
TP5 用cron实现linux定时任务 1) tp5的控制器内容: namespace app\test\controller; use think\Controller; use think\fa ...
- TP5 windows中执行定时任务
1 首先先写个自定义命令文件 比如 Test 2 在网站根目录下建立文件 crond.bat ,内容:(把你在cmd上操作流程写一遍) D: cd workspace\wamp\tp5 D:\PHPW ...
- ThinkPHP5实现定时任务
ThinkPHP5实现定时任务 最近使用ThinkPHP5做了个项目,项目中需要定时任务的功能,感觉有必要分享下 TP5做定时任务使用到command.php的 步骤如下: 1.配置command.p ...
- TP5 中的redis 队列
首先我们看一下自己的TP5的框架中的 TP5\vendor\topthink ,这个文件中有没有think-queue这个文件夹,如果没有请安装, 安装这个是要用到Composer的如果没有安装co ...
- Java定时任务的常用实现
Java的定时任务有以下几种常用的实现方式: 1)Timer 2)ScheduledThreadPoolExecutor 3)Spring中集成Cron Quartz 接下来依次介绍这几类具体实现的方 ...
- [转]Java实现定时任务的三种方法
在应用里经常都有用到在后台跑定时任务的需求.举个例子,比如需要在服务后台跑一个定时任务来进行非实时计算,清除临时数据.文件等.在本文里,我会给大家介绍3种不同的实现方法: 普通thread实现 Tim ...
- 使用python crontab设置linux定时任务
熟悉linux的朋友应该知道在linux中可以使用crontab设置定时任务.可以通过命令crontab -e编写任务.当然也可以直接写配置文件设置任务. 但是有时候希望通过脚本自动设置,比如我们应用 ...
- C#定时任务组件之FluentScheduler
FluentScheduler是.NET开源处理定时任务组件 1.任务的创建注册 public static void TaskActionByMinutes(Action action, int c ...
- 浅谈 linux 例行性工作 crontab (linux定时任务)
定时任务大家都挺说过,就好比你手机上的闹钟,到了指定的时候就会响起. 今天在对redis缓存进行定时储存时又操作了一把,发现一些细节,写的不好.大家就将就看吧, 首先 简单介绍一下linux 例行性工 ...
随机推荐
- Python面试题:使用栈处理括号匹配问题
括号匹配是栈应用的一个经典问题, 题目 判断一个文本中的括号是否闭合, 如: text = "({[({{abc}})][{1}]})2([]){({[]})}[]", 判断所有括 ...
- 利用django框架,手把手教你搭建数据可视化系统(一)
如何使用django去构建数据可视化的 web,可视化的结果可以呈现在web上. 使用django的MTV模型搭建网站 基础铺垫-MTV模型 Created with Raphaël 2.1.0Req ...
- dcokee 安装 nginx
1,docker pull openresty/openresty 2, mkdir /opt/local/openresty 等等文件夹 3, docker run --name=" ...
- django 快速实现登陆,接着注册的项目写(五)
1.改项目的urls.py from django.conf.urls import url,include from django.contrib import admin admin.autodi ...
- 使用selenium IDE 等一系列需要下载的东西的地址
转载来自:http://blog.csdn.net/u012246342/article/details/53005730 selenium 官网 IDE 等一系列 下载地址:http://www.s ...
- python操作Elasticsearch (一、例子)
E lasticsearch是一款分布式搜索引擎,支持在大数据环境中进行实时数据分析.它基于Apache Lucene文本搜索引擎,内部功能通过ReST API暴露给外部.除了通过HTTP直接访问El ...
- bpi English
一.Marketing and Management Dashboard 营销管理 1.non-stackable voucher 不可累计的券 2.Campaign engine 活动引擎 3.i ...
- 使用预设半透明鼠标Cursor
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- [Navicat]把1个库的数据迁移到另1个库--数据库备份
需求: 将autotest库中所包含的所有表,从连接centOS7复制1份至localhost.autotest 操作步骤: 1.将centOS7.autotest库中表结构及表数据转为sql语句:c ...
- unix进程通信方式总结(上)(转)
本文将<unix环境高级编程>一书中所涉及的几种重要的进程间通信方式(Inter-Process Communication)进行简单总结,总的来说,进程间通信有以下几种: ...