在控制器里面直接推送 就跟結(jié)合tp框架那樣直接調(diào)用 是需要自己去實(shí)現(xiàn)還是可以用gatewayworker去做?
解決方案:
直接用webman/push 插件,超級(jí)好用
http://wtbis.cn/doc/webman/plugin/push.html
https://wenda.workerman.net/question/6460 數(shù)據(jù)庫加載項(xiàng)從webman中獨(dú)立出來,單獨(dú)初始化,可以和webnan一個(gè)時(shí)間啟動(dòng).在webman 路徑可以隨便調(diào)用數(shù)據(jù)庫,不需要初始化和在composer 里做額外的工作.webman 昨天的問題已完美解決,有類似的問題歡迎兄弟們交流.謝謝兄弟們.
自定義命令行:
<?php
namespace app\command;
use GatewayWorker\BusinessWorker;
use GatewayWorker\Gateway;
use GatewayWorker\Register;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Workerman\Worker;
use Symfony\Component\Console\Input\InputArgument;
class GatewayCommand extends \Symfony\Component\Console\Command\Command
{
protected static $defaultName = 'config:gateway';
protected static $defaultDescription = 'gateway服務(wù)配置';
protected function configure()
{
$this
// 命令的名稱 ("php console_command" 后面的部分)
//->setName('model:create')
// 運(yùn)行 "php console_command list" 時(shí)的簡(jiǎn)短描述
->setDescription('Create new model')
// 運(yùn)行命令時(shí)使用 "--help" 選項(xiàng)時(shí)的完整命令描述
->setHelp('This command allow you to create models...')
// 配置一個(gè)參數(shù)
->addArgument('name', InputArgument::REQUIRED, 'what\'s model you want to create ?');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $argv;
// $argv[2] = 'start';
$argv[3] = '-d';
$output->writeln('gateway服務(wù)配置信息如下:');
$this->startGateWay();
$this->startBusinessWorker();
$this->startRegister();
Worker::runAll();
// $table = new Table($output);
// $table->setHeaders($headers);
// $table->setRows($row);
// $table->render();
return self::SUCCESS;
}
private function startBusinessWorker()
{
$worker = new BusinessWorker();
$worker->name = 'BusinessWorker';
$worker->count = 1;
$worker->registerAddress = '127.0.0.1:1237';
$worker->eventHandler = app_path() . "/service/Events.php";
}
private function startGateWay()
{
$gateway = new Gateway("websocket://0.0.0.0:2347");
$gateway->name = 'Gateway';
$gateway->count = 4;
$gateway->lanIp = '127.0.0.1';
$gateway->startPort = 40001;
$gateway->pingInterval = 30;
$gateway->pingNotResponseLimit = 0;
$gateway->pingData = '{"type":"ping"}';
$gateway->registerAddress = '127.0.0.1:1237';//正式 1237 測(cè)試 1236
}
private function startRegister()
{
new Register('text://0.0.0.0:1237');
}
}
自己會(huì)實(shí)現(xiàn)就自己實(shí)現(xiàn),不想自己實(shí)現(xiàn)或者不會(huì)就用gatewayworker唄