This commit is contained in:
2020-09-02 18:53:55 +08:00
parent 30f4a6a9a8
commit 089a6a0424
+25 -2
View File
@@ -25,6 +25,7 @@ use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake; use Snowflake\Snowflake;
use Swoole\Process; use Swoole\Process;
use HttpServer\Route\Annotation\Websocket as AWebsocket; use HttpServer\Route\Annotation\Websocket as AWebsocket;
use Swoole\Runtime;
/** /**
* Class Server * Class Server
@@ -75,15 +76,37 @@ class Server extends Application
$annotation->register('http', Annotation::class); $annotation->register('http', Annotation::class);
$annotation->register('websocket', AWebsocket::class); $annotation->register('websocket', AWebsocket::class);
$configs = $this->sortServers($configs); $this->enableCoroutine(true);
foreach ($configs as $server) { foreach ($this->sortServers($configs) as $server) {
$this->create($server); $this->create($server);
} }
$this->onProcessListener(); $this->onProcessListener();
return $this->getServer(); return $this->getServer();
} }
/**
* @param bool $isEnable
*/
private function enableCoroutine($isEnable = true)
{
if ($isEnable !== true) {
return;
}
Runtime::enableCoroutine(true, SWOOLE_HOOK_TCP |
SWOOLE_HOOK_UNIX |
SWOOLE_HOOK_UDP |
SWOOLE_HOOK_UDG |
SWOOLE_HOOK_SSL |
SWOOLE_HOOK_TLS |
SWOOLE_HOOK_SLEEP |
SWOOLE_HOOK_STREAM_FUNCTION |
SWOOLE_HOOK_PROC
);
}
/** /**
* @throws ReflectionException * @throws ReflectionException
* @throws ConfigException * @throws ConfigException