Thinkphp command使用
2023-03-29 23:03:03
410
0

第一步,配置command.php文件,目录在application/command.php

<?phpreturn ['app\home\command\Test',];

第二步,建立命令类文件,新建application/home/command/Test.php

<?phpnamespace app\home\command;use think\console\Command;use think\console\Input;use think\console\Output;class Test extends Command{protected function configure(){$this->setName('test')->setDescription('任务描述');}protected function execute(Input $input, Output $output){$output->writeln('请求时间:'.date('Y-m-d H:i:s'));//处理过程………………$output->writeln("TestCommand:");}}

第三步,打开cmd,进入到项目目录D:\phpstudy_pro\WWW\newweb
执行 php think Test

补充 thinkphp command
带参数
docker exec -it -u www-data cli /usr/local/bin/php /data/website/latest/abthink Test add_order
接收参数

protected function configure(){$this->setName('Test')->setDescription('数据上报');$this->addArgument("action", Argument::REQUIRED, "The name of the class");}protected function execute(Input $input, Output $output){$output->writeln('执行前---' . date("Y-m-d H:i:s", time()) . '<br>');$type = $input->getArgument("action");}
全部回帖(0)
加载中...