[SF] Symfony 在 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
[SF] Symfony 在 console 中结合 Workerman的更多相关文章
- [PHP]Symfony or Laravel 在 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 ...
- 浏览器console中加入jquery,测试选择元素
一.chrome浏览器F12打开调试界面,在console中输入(firefox同样可以): var jquery = document.createElement('script'); jquery ...
随机推荐
- 解决用低版本的客户端ORACLE 12提示ORA-28040的异常
用低版本的客户端访问ORACLE 12,无法连接,提示信息为ORA-28040.解决办法如下: 1.把sqlnet.ora文件添加两行(或者修改),修改文件后直接生效,不需要重启服务和监听的: SQL ...
- MySQL 5.7版本 sql_mode=only_full_group_by 问题
具体错误: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in ...
- kettle无法更新数据库字段解决办法
刚开始使用kettle,遇到一个问题, 在编写一个转换流程时,如果所操作的表字段名发生了变化(例如表student中id变更问userid),但是在kettle中使用时仍然显示是id,如下图, 此时清 ...
- pymsql简单的使用
不废话直接上代码: import pymysql class MysqlConnection: ''' 单例模式获取数据库链接实例 ''' _instance = None def __new__(c ...
- (转)配置、安装Apache24免装版
去过官网下载的应该都知道现在apache已经不提供.exe的一键安装程序的形式了,下载到的都只有免安装版本的. 首先下载,不在叙述.下载解压之后会得到如下的目录:. 1.进入:apache24le-- ...
- guava Lists.transform使用
作用:将一个List中的实体类转化为另一个List中的实体类. 稍微方便一点.例如:将List<Student>转化为List<StudentVo> Student: pack ...
- ROS多根adsl叠加负载均衡PCC的做法
命令行: / ip firewall mangle1.保证访问局域网IP的时候不被PCC了.add chain=prerouting dst-address=10.1.1.0/24 action=ac ...
- [UE4]计算箭头方向:正切、SetRelativeRotation、RotationFromXVector、Get MotionController Thumbstick X
正切 正弦函数 sinθ=y/r 余弦函数 cosθ=x/r 正切函数 tanθ=y/x 余切函数 cotθ=x/y 正割函数 secθ=r/x 余割函数 cscθ=r/y 已知y和x,求角度θ: ...
- iOS XML解析使用-韩国庆
欢迎-------(北京-iOS移动开发金牌教师QQ:2592675215)韩老师给你带来XML解析课程 今天给大家讲解下xml解析的第三方简单用法:首先我解释下,json和xml解析格式. JSON ...
- [php]php设计模式 (总结)
转载自[php]php设计模式 (总结) 传统的23种模式(没有区分简单工厂与抽象工厂) http://www.cnblogs.com/bluefrog/archive/2011/01/04/1925 ...