This commit is contained in:
as2252258@163.com
2021-03-23 02:29:48 +08:00
parent 433b71d20a
commit 807e8e25f7
5 changed files with 207 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace Rpc;
use Snowflake\Abstracts\Component;
use Snowflake\Abstracts\Config;
use Snowflake\Snowflake;
/**
* Class Service
* @package Rpc
*/
class Service extends Component
{
/**
* @throws \Snowflake\Exception\ConfigException
*/
public function instance(): void
{
$services = Config::get('rpc.service', false, []);
if (empty($services)) {
return;
}
$server = Snowflake::app()->getSwoole();
foreach ($services as $service) {
$mode = $service['mode'] ?? SWOOLE_SOCK_TCP6;
$rpcServer = $server->addlistener($service['host'], $service['port'], $mode);
$rpcServer->set([
'open_tcp_keepalive' => true,
'tcp_keepidle' => 30,
'tcp_keepinterval' => 10,
'tcp_keepcount' => 10,
'open_http_protocol' => false,
'open_websocket_protocol' => false,
]);
}
}
}