This commit is contained in:
2023-04-01 22:36:17 +08:00
parent a2a1699ef6
commit 12f70016e2
4 changed files with 295 additions and 63 deletions
+29 -39
View File
@@ -38,13 +38,13 @@ defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid');
*/
class Server extends HttpService
{
private mixed $daemon = 0;
/**
* @param State $state
* @param AsyncServer $manager
* @param CoroutineServer $manager
* @param ContainerInterface $container
* @param ProcessManager $processManager
* @param EventDispatch $dispatch
@@ -54,7 +54,7 @@ class Server extends HttpService
* @throws Exception
*/
public function __construct(public State $state,
public AsyncServer $manager,
public CoroutineServer $manager,
public ContainerInterface $container,
public ProcessManager $processManager,
public EventDispatch $dispatch,
@@ -64,8 +64,8 @@ class Server extends HttpService
{
parent::__construct($config);
}
/**
* @return void
* @throws ConfigException
@@ -77,15 +77,15 @@ class Server extends HttpService
return;
}
Coroutine::set([
'hook_flags' => (SWOOLE_HOOK_ALL | SWOOLE_HOOK_CURL) ^ SWOOLE_HOOK_BLOCKING_FUNCTION,
'hook_flags' => (SWOOLE_HOOK_ALL | SWOOLE_HOOK_CURL) ^ SWOOLE_HOOK_BLOCKING_FUNCTION,
'enable_deadlock_check' => FALSE,
'exit_condition' => function () {
'exit_condition' => function () {
return Coroutine::stats()['coroutine_num'] === 0;
}
]);
}
/**
* @param $process
* @throws Exception
@@ -94,8 +94,8 @@ class Server extends HttpService
{
$this->processManager->add($process);
}
/**
* @return void
* @throws ConfigException
@@ -110,8 +110,8 @@ class Server extends HttpService
$this->manager->onSignal(Config::get('signal', []));
$this->manager->start();
}
/**
* @return void
* @throws Exception
@@ -122,8 +122,8 @@ class Server extends HttpService
$this->provider->on(OnWorkerStart::class, [$this, 'setWorkerName']);
$this->provider->on(OnTaskerStart::class, [$this, 'setTaskerName']);
}
/**
* @param OnWorkerStart $onWorkerStart
* @throws ConfigException
@@ -135,11 +135,11 @@ class Server extends HttpService
}
$prefix = sprintf('Worker Process[%d].%d', $onWorkerStart->server->worker_pid, $onWorkerStart->workerId);
set_env('environmental', Kiri::WORKER);
Kiri::setProcessName($prefix);
}
/**
* @param OnTaskerStart $onWorkerStart
* @throws ConfigException
@@ -151,11 +151,11 @@ class Server extends HttpService
}
$prefix = sprintf('Tasker Process[%d].%d', $onWorkerStart->server->worker_pid, $onWorkerStart->workerId);
set_env('environmental', Kiri::TASK);
Kiri::setProcessName($prefix);
}
/**
* @return void
* @throws ConfigException
@@ -172,8 +172,8 @@ class Server extends HttpService
$this->router->scan_build_route();
}
}
/**
* @return void
* @throws ConfigException
@@ -189,8 +189,8 @@ class Server extends HttpService
}
$this->dispatch->dispatch(new OnShutdown());
}
/**
* @return bool
* @throws ConfigException
@@ -200,8 +200,8 @@ class Server extends HttpService
{
return $this->state->isRunner();
}
/**
* @param $daemon
* @return Server
@@ -214,14 +214,4 @@ class Server extends HttpService
$this->daemon = $daemon;
return $this;
}
/**
* @return HServer|SServer|WsServer|null
*/
#[Pure] public function getServer(): HServer|SServer|WsServer|null
{
return $this->manager->getServer();
}
}