在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的更多相关文章

  1. [PHP]Symfony or Laravel 在 console 中结合 Workerman

    在web框架的console中,命令不再是直接指定入口文件,如以往 php test.php start,而是类似 php app/console do 的形式. workerman 对命令的解析是 ...

  2. [转]使用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 ...

  3. .NET CORE——Console中使用依赖注入

    我们都知道,在 ASP.NET CORE 中通过依赖注入的方式来使用服务十分的简单,而在 Console 中,其实也只是稍微绕了个小弯子而已.不管是内置 DI 组件或者第三方的 DI 组件(如Auto ...

  4. YII2 console中引用其他模块(子项目)的model时出现model找不到命名空间的问题解决

    YII2 console中写定时任务, 想使用其他模块的model, 在 console的yii.php 入口文件中引入其他模块的配置文件, 否者会出现model等命名空间找不到的问题. 还有, 命名 ...

  5. Python3 tkinter基础 Frame bind 敲击键盘事件 将按键打印到console中

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. http所有请求头在Console中打印

    1.目标:将http中的请求头全部打印在Console中 2.基本语句 //1.获得指定的头 String header = response.getHeader("User-Agert&q ...

  7. 不能在Python Console中运行pytest

    在Python Console中运行pytest发现报错了 这是为什么?因为Python Console已经是进入python之后的环境,就像在python自带的IDLE中运行pytest pytes ...

  8. vue中export default 在console中是this.$vm

    vue中export default 在console中是this.$vm 用vue-cli搭出框架,用webstorm进行开发,参考vue2的官网进行教程学习, 在vue-cli中是用es6的exp ...

  9. 浏览器console中加入jquery,测试选择元素

    一.chrome浏览器F12打开调试界面,在console中输入(firefox同样可以): var jquery = document.createElement('script'); jquery ...

随机推荐

  1. MyCP课下作业

    任务详情 编写MyCP.java 实现类似Linux下cp XXX1 XXX2的功能,要求MyCP支持两个参数: java MyCP -tx XXX1.txt XXX2.bin 用来把文本文件(内容为 ...

  2. 左耳听风-ARTS-第2周(2019/3/31-2019/4/6)

    Algorithm 验证括号题(https://leetcode.com/problems/valid-parentheses/).这道题在极客时间上覃超的<算法面试通关40讲>(http ...

  3. python中使用redis实战

    from redis import StrictRedis rds = StrictRedis(host='127.0.0.1', port=6379, db=0, decode_responses= ...

  4. (C#)生成指定长度的随机字符串的通用方法

    .NET(C#)生成指定长度的随机字符串的通用方法,此方法可以指定字符串的长度,是否包含数字,是否包含符号,是否包含小写字母,是否包含大写字母等, 源码: #region 生成指定长度的随机字符串 / ...

  5. Eclipse Memory Analyzer 分析内存泄露

    OutOfMemoryError示例 代码 package com.walson.heap; import java.util.ArrayList;import java.util.List; /** ...

  6. [原创] JAVA 递归线程池测试 ExecutorService / ForkJoinPool

    测试工具使用递归的方式获取子进程的Msg消息,目前有2种常用的ExecutorService / ForkJoinPool 为了测试哪种效果较好,我们来写个测试Demo,循环5555555次+1(加锁 ...

  7. MTSC2018 | 确认过眼神,在这里能遇见Google、阿里、百度......

    MTSC2018部分Topic曝光啦 Google,阿里,百度,美团,小米,360,网易等公司是如何将技术转化为现实生产力,提高工作效率的?离开Saucelab的Jonathan又是如何规划Appiu ...

  8. 51nod 1162 质因子分解

    https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1162 数据范围大约是2^97,需要高精度计算 可以使用pollard- ...

  9. react的学习笔记

    React中几个核心的概念### 虚拟DOM(Virtual Document Object Model) + **DOM的本质是什么**:浏览器中的概念,用JS对象来表示 页面上的元素,并提供了操作 ...

  10. centos7安装rabbitmq3.7.9

    感谢此兄: https://blog.51cto.com/huwei555/2341513?source=dra  (centos7 安装rabbitmq 3.7) 以root用户登录.cd /hom ...