webman:创建控制台程序
一,相关文档
https://www.workerman.net/doc/webman/plugin/console.html
二,创建一个空的命令行程序
1,用webman命令创建
$ php webman make:command StatMonthCommand
Make command StatMonthCommand
2,命令行程序的默认代码:
<?php
namespace app\command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
class StatMonthCommand extends Command
{
protected static $defaultName = 'StatMonthCommand';
protected static $defaultDescription = 'StatMonthCommand';
/**
* @return void
*/
protected function configure()
{
$this->addArgument('name', InputArgument::OPTIONAL, 'Name description');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$name = $input->getArgument('name');
$output->writeln('Hello StatMonthCommand, '.$name);
return self::SUCCESS;
}
}
三,从命令行运行控制台程序:
运行时:
$ php webman StatMonthCommand '老刘'
Hello StatMonthCommand, 老刘