use GatewayWorker\BusinessWorker;
use GatewayWorker\Gateway;
use GatewayWorker\Register;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Config;
use Workerman\Worker;
/**
* GatewayWorker 命令行
*/
class GatewayWorker extends Command
{
protected function configure()
{
$this->setName('gateway')
->addArgument('service', Argument::OPTIONAL, 'workerman service: gateway|register|businessworker', null)
->addArgument('action', Argument::OPTIONAL, "start|stop|restart|reload|status|connections", 'start')
->addOption('host', 'H', Option::VALUE_OPTIONAL, 'the host of workerman server', null)
->addOption('port', 'P', Option::VALUE_OPTIONAL, 'the port of workerman server', null)
->addOption('daemon', 'd', Option::VALUE_OPTIONAL, 'Run the workerman server in daemon mode.')
->setDescription('GatewayWorker Server for ThinkPHP');
}
public function execute(Input $input, Output $output)
{
$service = $input->getArgument('service');
$action = $input->getArgument('action');
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace app\common\business;
use GatewayWorker\Lib\Gateway;
use think\worker\Application;
use Workerman\Worker;
/**
* Worker 命令行服务类
*/
class Events
{
/**
* onWorkerStart 事件回调
* 当businessWorker进程启动时触发。每个进程生命周期内都只会触发一次
*
* @access public
* @param \Workerman\Worker $businessWorker
* @return void
*/
public static function onWorkerStart(Worker $businessWorker)
{
$app = new Application;
$app->initialize();
}
/**
* onConnect 事件回调
* 当客户端连接上gateway进程时(TCP三次握手完毕时)触发
*
* @access public
* @param int $client_id
* @return void
*/
public static function onConnect($client_id)
{
Gateway::sendToCurrentClient("Your client_id is a $client_id");
}
3 个回复
风扬
赞同来自:
这是控制台:



这是代码:
GatewayWorker.php
Event.php
下面两行写入log文件都有内容,但是上面那行var_dump的打印在控制台就是看不到
six
赞同来自:
建议用纯净版gatewayWorker试下,感觉是输出被tp给隐藏了
小伍 - 95后
赞同来自:
var_export用这个打印看看