[PHP]Symfony or Laravel 在 console 中结合 Workerman
在web框架的console中,命令不再是直接指定入口文件,如以往 php test.php start,而是类似 php app/console do 的形式。
workerman 对命令的解析是 parseCommand 方法,里面主要是处理 $argv 全局变量。
那么我们只需要在自己的逻辑中对其重新赋值,满足 $argv[1] 是动作 start | stop | restart | ... 即可,那么剩余workerman参数就是 $argv[2],依次类推。
Symfony2 command:
namespace AppBundle\Command; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Workerman\Connection\TcpConnection;
use Workerman\Worker; /**
* @author farwish <farwish(a)foxmail.com>
*
* Class DataWorkerCommand
* @package AppBundle\Command
*/
class DataWorkerCommand extends BaseCommand
{
public function configure()
{
$this->setName('xc:data:worker')
->setDescription('启动服务')
->addArgument(
'subcommands',
InputArgument::IS_ARRAY,
'可选多个参数'
)
;
} /**
* app/console xc:data:worker start d [g]
* app/console xc:data:worker stop
* app/console xc:data:worker status
* app/console xc:data:worker restart d [g]
*
* @param InputInterface $input
* @param OutputInterface $output
*/
public function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output); global $argv; /* Original data like
Array
(
[0] => worker.php
[1] => start
[2] => -d
[3] => -g
)
*/
/* Console data like
Array
(
[0] => app/console
[1] => xc:data:worker
[2] => start
[3] => d
[4] => g
)
*/ // So redefine arguments
if (isset($argv[2])) {
$argv[1] = $argv[2];
if (isset($argv[3])) {
$argv[2] = "-{$argv[3]}";
if (isset($argv[4])) {
$argv[3] = "-{$argv[4]}";
} else {
unset($argv[3]);
}
} else {
unset($argv[2]);
}
} // worker
$worker = new Worker("websocket://0.0.0.0:9000"); $worker->count = 4; $worker->onMessage = function ($connection, $data)
{
/* @var TcpConnection $connection */
$connection->send('hello');
}; Worker::runAll();
}
}
Thats all.
Link: http://www.cnblogs.com/farwish/p/7988617.html
[PHP]Symfony or Laravel 在 console 中结合 Workerman的更多相关文章
- [SF] Symfony 在 console 中结合 Workerman
在web框架的console中,命令不再是直接指定入口文件,如以往 php test.php start,而是类似 php app/console do 的形式. workerman 对命令的解析是 ...
- [转]使用Maven添加依赖项时(Add Dependency)时,没有提示项目可用,并且在Console中,输出: Unable to update index for central|http://repo1.maven.org/maven2 。
使用Maven添加依赖项时(Add Dependency)时,没有提示项目可用,并且在Console中,输出: Unable to update index for central|http://re ...
- .NET CORE——Console中使用依赖注入
我们都知道,在 ASP.NET CORE 中通过依赖注入的方式来使用服务十分的简单,而在 Console 中,其实也只是稍微绕了个小弯子而已.不管是内置 DI 组件或者第三方的 DI 组件(如Auto ...
- YII2 console中引用其他模块(子项目)的model时出现model找不到命名空间的问题解决
YII2 console中写定时任务, 想使用其他模块的model, 在 console的yii.php 入口文件中引入其他模块的配置文件, 否者会出现model等命名空间找不到的问题. 还有, 命名 ...
- Python3 tkinter基础 Frame bind 敲击键盘事件 将按键打印到console中
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- http所有请求头在Console中打印
1.目标:将http中的请求头全部打印在Console中 2.基本语句 //1.获得指定的头 String header = response.getHeader("User-Agert&q ...
- 不能在Python Console中运行pytest
在Python Console中运行pytest发现报错了 这是为什么?因为Python Console已经是进入python之后的环境,就像在python自带的IDLE中运行pytest pytes ...
- vue中export default 在console中是this.$vm
vue中export default 在console中是this.$vm 用vue-cli搭出框架,用webstorm进行开发,参考vue2的官网进行教程学习, 在vue-cli中是用es6的exp ...
- Laravel 5.2 中多用户认证实现(前台和后台登录)
Laravel 5.2中多用户认证支持,即同时允许不同数据表用户(如前台用户.后台用户.app用户等)登录认证.下面我们就来简单介绍多用户登录及注册功能实现. 1.生成认证脚手架 首先我们使用Lara ...
随机推荐
- LINUX 笔记-Shell 脚本控制语句
1.if 语句 if condition1;then command1 elif condition2;then command2 else command3 fi 2.case 语句 case va ...
- css 文字和子元素水平垂直居中
关于水平垂直居中,这是一个很简单的问题,但是很多时候,往往简单的东西,反而做不出来.这就是基础不扎实的缘故吧,我参照一些资料,总结了水平垂直居中的几种方法如下: 1 .文字水平垂直居中 这个比较简单, ...
- MongoDB全文检索
1. 全文检索概念: 全文检索是对每一个词建立一个索引,指明该词在文章中出现的次数和位置,当用户查询时,检索程序就根据事先建立的索引进行查找,并将查找的结果反馈给用户的检索方式. (暂时不支持中文) ...
- Vue.js之render函数基础
刚才翻了一下博客,才发现,距离自己写的第一篇Vue的博客vue.js之绑定class和style(2016-10-30)已经过去一年零两天.这一年里,自己从船厂的普通技术员,成为了一个微型不靠谱创业公 ...
- 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest A Email Aliases(模拟STL vector+map)
Email AliasesCrawling in process... Crawling failed Time Limit:2000MS Memory Limit:524288KB ...
- linux进程资源占用高原因分析命令记录
1.查看进程的线程: ps -eLf|egrep 'gateserver|UID' 2.跟踪线程调用: strace -p 15530 3.统计线程中函数的调用小号CPU时间: strace -p 1 ...
- 【每天半小时学框架】——React.js的模板语法与组件概念
[重点提前说:组件化与虚拟DOM是React.js的核心理念!] 先抛出一个论题:在React.js中,JSX语法提倡将 HTML 和 CSS 全都写入到JavaScrip ...
- 0_Simple__cppIntegration
引用已经编好的 .cu 和 .cpp 代码来混合使用.在 main.cpp 中调用了使用GPU的 cppIntegration.cu (测试函数也在其中) 和使用CPU的 cppIntegration ...
- 利用PowerShell 得到 进程总共占用的内存
$task = tasklist /nh /fo csv $total = 0 for($i=0; $i -lt $task.count; $i++) { $one = $task[ $i ].Spl ...
- zip 安装mysql 和遇到的坑
在官网下载了mysql 社区版的,官方网址:https://dev.mysql.com/downloads/mysql/ 解压后发现里面没有安装快捷方式,才知道是zip解压,dos窗口安装.这就比界面 ...