TP6的计划任务设置
1.设置项目中/config/console.php文件
<?php
// +----------------------------------------------------------------------
// | 控制台配置
// +----------------------------------------------------------------------
return [
// 指令定义 commands 控制器名字
'commands' => [
'football' => 'app\command\Football', // 指定文件
],
];
2.创建对应的控制器 command文件夹 创建对应的文件Football.php
<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Db; // 数据库的链接
class Football extends Command
{
protected function configure()
{
$this->setName('Football')->addArgument('test')->setDescription('Here is the remark ');
}
protected function execute(Input $input, Output $output)
{
switch ($input->getArgument('test')) {
case 'reward':
self::reward($input, $output);
break;
default:
self::clock($input, $output);
break;
}
}
protected static function reward(Input $input, Output $output)
{
Db::name('user')->where('is_pay',1)->order('id desc')->chunk(50, function($user) {
foreach ($user as $key => $value) {
}
});
}
}3.在宝塔计划任务里面添加任务
Path=/www/wwwroot/xxx
cd $Path
php think football reward
// football什么任务 任务方法
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果