请问workerman-thrift-rpc如何启动多个服务?

zhongzhen

图片
 如果要同时启动HelloWorld,HelloWorld2,HelloWorld3 服务,是这样写吗?

$worker = new ThriftWorker('tcp://0.0.0.0:8000');
$worker->count = 1;
$worker->class = 'HelloWorld';

$worker = new ThriftWorker('tcp://0.0.0.0:8001');
$worker->count = 1;
$worker->class = 'HelloWorld2';

$worker = new ThriftWorker('tcp://0.0.0.0:8002');
$worker->count = 1;
$worker->class = 'HelloWorld3';

如果要启动的服务很多,岂不是要写很多这样的代码,请问有更好的处理方式吗?真实的工作环境是怎么处理的?
 
然后还想请教个问题,如果服务的进程因为某种原因挂了,workman会怎么处理呢?如果再次生成新的服务,它的端口号会变吗?如果变了,客户端还是连的原来的端口,岂不是就报错了,如果那样应该怎么办呢?
 
麻烦了,谢谢。

3080 2 0
2个回答

wangn

你可以仿照一个demo 核心代码  // 标记是全局启动

define('GLOBAL_START', 1);

require_once __DIR__ . '/vendor/autoload.php';

// 加载所有Applications/*/start.php,以便启动所有服务
foreach(glob(__DIR__.'/Applications/*/start*.php') as $start_file)
{
    require_once $start_file;
}

//运行所有服务

Worker::runAll();
  • 暂无评论
taozywu

@zhongzhen

<?php

$configs = array(
   array(
      "uri" => "tcp://0.0.0.0:8000", "class" => "HelloWorld1",
   ),
   array(
      "uri" => "tcp://0.0.0.0:8001", "class" => "HelloWorld2",
   ),
   array(
      "uri" => "tcp://0.0.0.0:8002", "class" => "HelloWorld3",
   )
);

foreach ($configs as $c) {

   $worker = new ThriftWorker($c);
   $worker->count = 1;
   $worker->class = $c;

   // input your code @todo
}
  • 暂无评论
年代过于久远,无法发表回答
×
🔝