需求场景:
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.配置任务计划程序