1
This commit is contained in:
+40
@@ -5,6 +5,7 @@ namespace Server;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Http\Handler\Abstracts\HttpService;
|
use Http\Handler\Abstracts\HttpService;
|
||||||
|
use Http\Handler\Router;
|
||||||
use Kiri\Abstracts\Config;
|
use Kiri\Abstracts\Config;
|
||||||
use Kiri\Events\EventDispatch;
|
use Kiri\Events\EventDispatch;
|
||||||
use Kiri\Exception\ConfigException;
|
use Kiri\Exception\ConfigException;
|
||||||
@@ -13,6 +14,7 @@ use Kiri\Annotation\Inject;
|
|||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Server\Events\OnShutdown;
|
use Server\Events\OnShutdown;
|
||||||
|
use Swoole\Coroutine;
|
||||||
|
|
||||||
|
|
||||||
defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid');
|
defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid');
|
||||||
@@ -81,6 +83,44 @@ class Server extends HttpService
|
|||||||
return $this->manager()->getServer()->start();
|
return $this->manager()->getServer()->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ConfigException
|
||||||
|
*/
|
||||||
|
private function configure_set()
|
||||||
|
{
|
||||||
|
$enable_coroutine = Config::get('servers.settings.enable_coroutine', false);
|
||||||
|
Config::set('servers.settings.enable_coroutine', true);
|
||||||
|
if ($enable_coroutine != true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Coroutine::set([
|
||||||
|
'hook_flags' => SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_BLOCKING_FUNCTION,
|
||||||
|
'enable_deadlock_check' => FALSE,
|
||||||
|
'exit_condition' => function () {
|
||||||
|
return Coroutine::stats()['coroutine_num'] === 0;
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
* @throws ConfigException
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
* @throws \ReflectionException
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function runtime_start(): void
|
||||||
|
{
|
||||||
|
$this->configure_set();
|
||||||
|
|
||||||
|
$this->container->get(Router::class)->read_files();
|
||||||
|
|
||||||
|
$this->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
|
|||||||
+8
-6
@@ -63,19 +63,21 @@ class ServerCommand extends Command
|
|||||||
{
|
{
|
||||||
$manager = Kiri::app()->getServer();
|
$manager = Kiri::app()->getServer();
|
||||||
$manager->setDaemon((int)!is_null($input->getOption('daemon')));
|
$manager->setDaemon((int)!is_null($input->getOption('daemon')));
|
||||||
if (is_null($input->getArgument('action'))) {
|
|
||||||
|
$action = $input->getArgument('action');
|
||||||
|
if (is_null($action)) {
|
||||||
throw new Exception('I don\'t know what I want to do.');
|
throw new Exception('I don\'t know what I want to do.');
|
||||||
}
|
}
|
||||||
if (!in_array($input->getArgument('action'), self::ACTIONS)) {
|
if (!in_array($action, self::ACTIONS)) {
|
||||||
throw new Exception('I don\'t know what I want to do.');
|
throw new Exception('I don\'t know what I want to do.');
|
||||||
}
|
}
|
||||||
if ($input->getArgument('action') == 'restart') {
|
if ($action == 'restart' || $action == 'stop') {
|
||||||
$manager->shutdown();
|
$manager->shutdown();
|
||||||
|
if ($action == 'stop') {
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
if ($input->getArgument('action') != 'stop') {
|
|
||||||
return $this->generate_runtime_builder($manager);
|
|
||||||
}
|
}
|
||||||
$manager->shutdown();
|
$manager->runtime_start();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user