在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. git代理配置

    命令行模式下配置 git config --global https.proxy https://proxyuser:proxypassword@ip/域名:port git config --glo ...

  2. 优化IIS7.5支持10万个同时请求的配置方法

    通过对IIS7的配置进行优化,调整IIS7应用池的队列长度,请求数限制,TCPIP连接数等方面,从而使WEB服务器的性能得以提升,保证WEB访问的访问流畅. IIS7.5是微软推出的最新平台IIS,性 ...

  3. Sqlserver 计算两坐标距离函数

    mark if exists (select * from dbo.sysobjects where id = object_id(N'UF_ETL_GetDistance') and xtype i ...

  4. iOS 12 tabbar 从二级页面返回时,出现跳动解决办法

    APP push一个界面,返回的时候,tabBar上的图标和文字出现一个从上往下的神奇动画 经过测试发现,如果使用系统OS12.1 UINavigationController + UITabBarC ...

  5. Google SketchUp Cookbook: (Chapter 4) Advanced Intersect and Follow Me Techniques

    软件环境 SketchUp Pro 2018 参考书籍 Google SketchUp Cookbook Intersect 工具经常与 Follow Me 工具一起使用,以创建复杂的 3D 物体. ...

  6. Java读取Excel并与SqlServer库中的数据比较

    先说说需求.在SQL server数据库中的表里存在一些数据,现在整理的Excel文档中也存在一些数据,现在需要通过根据比较某个字段值(唯一)来判断出,在库中有但excel中没有的数据. 大概的思路就 ...

  7. sqlserver 已星期一为第一天统计周

    本文来源:https://blog.csdn.net/sqlserverdiscovery/article/details/53080695 SELECT GETDATE() AS THEDAY, c ...

  8. 极速认识RSS!

    在解释RSS是什么之前,让我先来举个栗子. 大家都能在街道看到许多海报栏.在那里,会贴出各种各样最新的消息,比如哪个系要开讲座了.星期二晚上的电影放什么.二手货转让等 等.只要看一下海报栏,就会对学校 ...

  9. Chapter07 链表(下):如何轻松学出正确的链表代码?

    技巧一:理解指针或引用的含义 技巧二:指针丢失和内存泄漏 技巧三:利用哨兵简化实现难度 技巧四:重点留意边界条件处理 如果链表未空时,代码是否能够正常运行 如果链表只包含一个节点时,代码能否正常运行 ...

  10. 如何在vue+element中实现选择框和穿梭框的根据拼音以及拼音首字母以及汉字的模糊搜索

    1.汉字: 直接添加对应的 filterable     2.拼音: 穿梭框和选择器的实现方式有所不同   选择器:   <1>下载pinyin-match:   npm i --save ...