ThinkPHP 定时任务"/>
解决小问题:ThinkPHP 定时任务
需求场景:
TP5 需要定时统计数据,部署目标为云虚拟主机,没有宝塔环境。
解决思路:用离线电脑访问在线接口,配合Linux Shell /Windows 计划任务 配置定时任务;
一、Windows
1.搭建好TP5环境
省略
2.创建Command
namespace app\index\command;use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Log;class Task extends Command
{protected function configure(){$this->setName('Task')->setDescription("测试");}protected function execute(Input $input, Output $output){Log::write(' hello Task','error');}}
3.配置app/command.php
return ['app\index\command\Task'
];
4.编写phptask.bat
E:
cd \code-action\php-action\fast02
D:\phpstudy_pro\Extensions\php\php7.1.9nts\php.exe think Task
5.配置任务计划程序
根据自己任务需求设定时间周期
选择bat执行文件
6.查看日志
runtime/log/2021[月份] / 日期.log
二。Linux (Centos)
原理一样 细节待整理
更多推荐
解决小问题:ThinkPHP 定时任务
发布评论