在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. Zuul网关总结

    Zuul是Netflix开源的网关服务(gateway service)(https://github.com/Netflix/zuul),提供动态路由.监控.弹性.安全性等功能.最近在公司的项目中用 ...

  2. 我发起了一个 用 javascript 写一个 Office 的 开源项目 JS Office

    用   js  写   Office,  说实在的,  把 现在已有的 各种 富文本编辑器 和 电子表格 js 库 收集起来 整合一下 就 差不多了 , 放到 前几天 那个 “  js 作为 一等公民 ...

  3. Oracle 相关知识

    1.Navicat 连接Oracle 报错: 解决办法: 1).先下载oracle客户端,win64_11gR2_client.zip,下载地址:http://www.oracle.com/techn ...

  4. update_engine-DownloadAction(一)

    通过update_engine-整体结构(一),(二),(三)对update_engine整体的运行机制有了一定的认识之后.开始逐个分析重要的Action.先从DownloadAction开始分析. ...

  5. debian shell脚本关联

    懒得命令行一个个的输 设置,MIME类型编辑,搜索x-shellscript,默认的改成/bin/bash即可

  6. python基础知识17---装饰器2

    函数式编程复习: def map_test(func,array): array_new=[] for i in array: array_new.append(func(i)) return arr ...

  7. Python3.4 枚举类型的使用

    From: https://majing.io/posts/10000005131196 枚举类型是在Python3.4新增到Python的标准库. 创建枚举 Python提供了两种方法来创建枚举: ...

  8. 树莓派中学TensorFlow

    树莓派中默认的虚拟环境为python 2.x,需要用下面的-p参数修改为python3环境.电信wifi和公司网络直接用pip3 install TensorFlow都不好使,用联通手机热点可以安装. ...

  9. 搭建Mock Server

    1.为什么要搭建mock-server? 为了更好的分工合作,让前端能在不依赖后端环境的情况下进行开发,其中一种手段就是为前端开发者提供一个 web 容器,这个本地环境就是 mock-server. ...

  10. RESTful levels、HATEOAS

    概述: REST(英文:Representational State Transfer,简称REST)描述了一个架构样式的网络系统,比如 web 应用程序.它首次出现在 2000 年 Roy Fiel ...