ThinkPHP5.0框架自定义命令行
2018-09-05 14:52
471 查看
Swoole是PHP的异步、并行、高性能网络通信引擎,使用纯C语言编写,提供了PHP语言的异步多线程服务器,异步TCP/UDP网络客户端,异步MySQL,异步Redis,数据库连接池,AsyncTask,消息队列,毫秒定时器,异步文件读写,异步DNS查询。 Swoole内置了Http/WebSocket服务器端/客户端、Http2.0服务器端/客户端。
上面只是官方概念!
我在项目中主要使用Swoole拓展实现消息队列,挺高任务的执行效率。
框架环境:ThinkPHP 5.0
第一部分:ThinkPHP5.0框架自定义命令行配置
配置command.php文件,目录在application/command.php。
建立命令类文件,新建application/console/command/Test.php。
复制代码
在框架的目录下面运行命令
至此,自定义命令行已经完成!
上面只是官方概念!
我在项目中主要使用Swoole拓展实现消息队列,挺高任务的执行效率。
框架环境:ThinkPHP 5.0
第一部分:ThinkPHP5.0框架自定义命令行配置
配置command.php文件,目录在application/command.php。
return [ 'app\console\command\Test', ];
建立命令类文件,新建application/console/command/Test.php。
复制代码
<?php /** * Created by PhpStorm. * User: 小良 * Date: 2017/7/24 * Time: 10:55 */ namespace app\console\command; use think\console\Command; use think\console\Input; use think\console\input\Argument; use think\console\input\Option; use think\console\Output; class Test extends Command{ /** * 定义命令 * 命令名称是 test */ protected function configure() { //设置参数 $this->addArgument('email', Argument::REQUIRED); //必传参数 $this->addArgument('mobile', Argument::OPTIONAL);//可选参数 //选项定义 $this->addOption('message', 'm', Option::VALUE_REQUIRED, 'test'); //选项值必填 $this->addOption('status', 's', Option::VALUE_OPTIONAL, 'test'); //选项值选填 $this->setName('test')->setDescription('Here is the remark '); } /** * 命令执行的内容 * @param Input $input * @param Output $output */ protected function execute(Input $input, Output $output) { //获取参数值 $args = $input->getArguments(); $output->writeln('The args value is:'); print_r($args); //获取选项值 $options = $input->getOptions(); $output->writeln('The options value is:'); print_r($options); $output->writeln("TestCommand:"); $output->writeln("End.."); } }
在框架的目录下面运行命令
php think test email mobile -m"mtset" -s"stest"
至此,自定义命令行已经完成!
相关文章推荐
- 商淘软件:以wstmart开源商城系统说明ThinkPHP 5.0如何实现自定义404(异常处理)页面
- thinkPHP5.0框架命名空间详解
- ThinkPHP5.0更改框架的验证方法:对象->validate(true)->save();
- thinkPHP5.0框架安装教程
- thinkPHP5.0框架验证码调用及点击图片刷新简单实现方法
- ThinkPHP5.0框架下多对多关联模型的增删改查
- thinkPHP5.0框架事务处理操作简单示例
- 商淘软件:ThinkPHP 5.0如何实现自定义404(异常处理)页面
- ThinkPHP3.2框架自定义配置和加载用法示例
- thinkPHP5框架自定义验证器实现方法分析
- thinkPHP5.0框架环境变量配置方法
- thinkphp5.0自定义验证规则使用方法
- Thinkphp5.0框架,wamp服务器配置子域名
- thinkPHP5.0框架开发规范简介
- ThinkPHP框架配置自定义的模板变量(十)
- 利用THINKPHP框架开发的自定义表单及数据字典模板
- thinkphp5.0开发实战基础--如何使用框架
- thinkPHP5.0框架模块设计详解
- 最新基于ThinkPHP5.0+BootStrap框架开发的自适应WAP手机端响应式界面博客系统PHP源码
- 基于thinkphp5.0的后台框架