Compare commits

...

2 Commits

Author SHA1 Message Date
as2252258 b2728947a3 Revert "改名"
This reverts commit fdf58326
2022-01-10 11:39:55 +08:00
as2252258 8ec5b0e8d8 1 2022-01-09 17:56:47 +08:00
45 changed files with 137 additions and 95 deletions
+2 -2
View File
@@ -1,10 +1,10 @@
<?php <?php
namespace Server\Abstracts; namespace Kiri\Server\Abstracts;
use Kiri\Context; use Kiri\Context;
use Server\Contract\OnProcessInterface; use Kiri\Server\Contract\OnProcessInterface;
use Swoole\Coroutine; use Swoole\Coroutine;
use Swoole\Process; use Swoole\Process;
+1 -1
View File
@@ -1,7 +1,7 @@
<?php <?php
namespace Server\Abstracts; namespace Kiri\Server\Abstracts;
use Kiri\Annotation\Inject; use Kiri\Annotation\Inject;
+1 -1
View File
@@ -1,7 +1,7 @@
<?php <?php
namespace Server; namespace Kiri\Server;
/** /**
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Contract; namespace Kiri\Server\Contract;
interface OnBeforeShutdown interface OnBeforeShutdown
{ {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Contract; namespace Kiri\Server\Contract;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Contract; namespace Kiri\Server\Contract;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Contract; namespace Kiri\Server\Contract;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Contract; namespace Kiri\Server\Contract;
use Swoole\Http\Request; use Swoole\Http\Request;
use Swoole\Http\Response; use Swoole\Http\Response;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Contract; namespace Kiri\Server\Contract;
use Kiri\Websocket\WebSocketInterface; use Kiri\Websocket\WebSocketInterface;
use Swoole\WebSocket\Frame; use Swoole\WebSocket\Frame;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Contract; namespace Kiri\Server\Contract;
use Swoole\Http\Request; use Swoole\Http\Request;
+2 -2
View File
@@ -1,8 +1,8 @@
<?php <?php
namespace Server\Contract; namespace Kiri\Server\Contract;
use Server\Abstracts\Server; use Kiri\Server\Abstracts\Server;
interface OnPacketInterface interface OnPacketInterface
{ {
+1 -1
View File
@@ -1,7 +1,7 @@
<?php <?php
namespace Server\Contract; namespace Kiri\Server\Contract;
/** /**
+1 -1
View File
@@ -1,7 +1,7 @@
<?php <?php
namespace Server\Contract; namespace Kiri\Server\Contract;
use Swoole\Process; use Swoole\Process;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Contract; namespace Kiri\Server\Contract;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,7 +1,7 @@
<?php <?php
namespace Server\Contract; namespace Kiri\Server\Contract;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
class OnAfterWorkerStart class OnAfterWorkerStart
{ {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
class OnBeforeWorkerStart class OnBeforeWorkerStart
{ {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
class OnServerBeforeStart class OnServerBeforeStart
{ {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Events; namespace Kiri\Server\Events;
use Swoole\Server; use Swoole\Server;
+3 -3
View File
@@ -1,11 +1,11 @@
<?php <?php
namespace Server\Handler; namespace Kiri\Server\Handler;
use Kiri\Annotation\Inject; use Kiri\Annotation\Inject;
use Server\Abstracts\Server; use Kiri\Server\Abstracts\Server;
use Exception; use Exception;
use Server\Contract\OnPipeMessageInterface; use Kiri\Server\Contract\OnPipeMessageInterface;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
/** /**
+5 -5
View File
@@ -1,15 +1,15 @@
<?php <?php
namespace Server\Handler; namespace Kiri\Server\Handler;
use Kiri\Annotation\Inject; use Kiri\Annotation\Inject;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use ReflectionException; use ReflectionException;
use Server\Abstracts\Server; use Kiri\Server\Abstracts\Server;
use Server\Events\OnBeforeShutdown; use Kiri\Server\Events\OnBeforeShutdown;
use Server\Events\OnShutdown; use Kiri\Server\Events\OnShutdown;
use Server\Events\OnStart; use Kiri\Server\Events\OnStart;
/** /**
+4 -4
View File
@@ -1,14 +1,14 @@
<?php <?php
namespace Server\Handler; namespace Kiri\Server\Handler;
use Kiri\Annotation\Inject; use Kiri\Annotation\Inject;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use ReflectionException; use ReflectionException;
use Server\Abstracts\Server; use Kiri\Server\Abstracts\Server;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Server\Events\OnManagerStart; use Kiri\Server\Events\OnManagerStart;
use Server\Events\OnManagerStop; use Kiri\Server\Events\OnManagerStop;
/** /**
+3 -3
View File
@@ -1,11 +1,11 @@
<?php <?php
namespace Server\Handler; namespace Kiri\Server\Handler;
use Kiri\Annotation\Inject; use Kiri\Annotation\Inject;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use Server\Events\OnAfterReload; use Kiri\Server\Events\OnAfterReload;
use Server\Events\OnBeforeReload; use Kiri\Server\Events\OnBeforeReload;
use Swoole\Server; use Swoole\Server;
+8 -8
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server\Handler; namespace Kiri\Server\Handler;
use Exception; use Exception;
use Kiri\Abstracts\Config; use Kiri\Abstracts\Config;
@@ -8,13 +8,13 @@ use Kiri\Core\Help;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use Kiri\Kiri; use Kiri\Kiri;
use Kiri\Annotation\Inject; use Kiri\Annotation\Inject;
use Server\Events\OnAfterWorkerStart; use Kiri\Server\Events\OnAfterWorkerStart;
use Server\Events\OnBeforeWorkerStart; use Kiri\Server\Events\OnBeforeWorkerStart;
use Server\Events\OnTaskerStart as OnTaskStart; use Kiri\Server\Events\OnTaskerStart as OnTaskStart;
use Server\Events\OnWorkerError; use Kiri\Server\Events\OnWorkerError;
use Server\Events\OnWorkerExit; use Kiri\Server\Events\OnWorkerExit;
use Server\Events\OnWorkerStart; use Kiri\Server\Events\OnWorkerStart;
use Server\Events\OnWorkerStop; use Kiri\Server\Events\OnWorkerStop;
use Swoole\Server; use Swoole\Server;
use Swoole\Timer; use Swoole\Timer;
+44 -4
View File
@@ -1,10 +1,11 @@
<?php <?php
namespace Server; namespace Kiri\Server;
use Exception; use Exception;
use Http\Handler\Abstracts\HttpService; use Kiri\Message\Handler\Abstracts\HttpService;
use Kiri\Message\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;
@@ -12,7 +13,8 @@ use Kiri\Kiri;
use Kiri\Annotation\Inject; 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 Kiri\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,8 +83,46 @@ 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
* @throws ConfigException * @throws ConfigException
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
+11 -9
View File
@@ -1,7 +1,7 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Server; namespace Kiri\Server;
use Exception; use Exception;
@@ -63,20 +63,22 @@ 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') { $manager->runtime_start();
return $this->generate_runtime_builder($manager); return 0;
}
$manager->shutdown();
return 0;
} }
+17 -17
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server; namespace Kiri\Server;
use Exception; use Exception;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
@@ -13,22 +13,22 @@ use Kiri\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use ReflectionException; use ReflectionException;
use Server\Abstracts\BaseProcess; use Kiri\Server\Abstracts\BaseProcess;
use Server\Contract\OnCloseInterface; use Kiri\Server\Contract\OnCloseInterface;
use Server\Contract\OnConnectInterface; use Kiri\Server\Contract\OnConnectInterface;
use Server\Contract\OnDisconnectInterface; use Kiri\Server\Contract\OnDisconnectInterface;
use Server\Contract\OnHandshakeInterface; use Kiri\Server\Contract\OnHandshakeInterface;
use Server\Contract\OnMessageInterface; use Kiri\Server\Contract\OnMessageInterface;
use Server\Contract\OnPacketInterface; use Kiri\Server\Contract\OnPacketInterface;
use Server\Contract\OnProcessInterface; use Kiri\Server\Contract\OnProcessInterface;
use Server\Contract\OnReceiveInterface; use Kiri\Server\Contract\OnReceiveInterface;
use Server\Events\OnServerBeforeStart; use Kiri\Server\Events\OnServerBeforeStart;
use Server\Handler\OnPipeMessage; use Kiri\Server\Handler\OnPipeMessage;
use Server\Handler\OnServer; use Kiri\Server\Handler\OnServer;
use Server\Handler\OnServerManager; use Kiri\Server\Handler\OnServerManager;
use Server\Handler\OnServerReload; use Kiri\Server\Handler\OnServerReload;
use Server\Handler\OnServerWorker; use Kiri\Server\Handler\OnServerWorker;
use Server\Tasker\OnServerTask; use Kiri\Server\Tasker\OnServerTask;
use Swoole\Http\Server as HServer; use Swoole\Http\Server as HServer;
use Swoole\Process; use Swoole\Process;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,7 +1,7 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Server; namespace Kiri\Server;
use Exception; use Exception;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server; namespace Kiri\Server;
use Exception; use Exception;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server; namespace Kiri\Server;
use Swoole\Server; use Swoole\Server;
+3 -3
View File
@@ -1,14 +1,14 @@
<?php <?php
namespace Server\Tasker; namespace Kiri\Server\Tasker;
use Exception; use Exception;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
use Kiri\Core\HashMap; use Kiri\Core\HashMap;
use Kiri\Kiri; use Kiri\Kiri;
use ReflectionException; use ReflectionException;
use Server\Contract\OnTaskInterface; use Kiri\Server\Contract\OnTaskInterface;
use Server\SwooleServerInterface; use Kiri\Server\SwooleServerInterface;
/** /**
+2 -2
View File
@@ -1,13 +1,13 @@
<?php <?php
namespace Server\Tasker; namespace Kiri\Server\Tasker;
use Kiri\Annotation\Inject; use Kiri\Annotation\Inject;
use Kiri\Abstracts\Logger; use Kiri\Abstracts\Logger;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Server\Contract\OnTaskInterface; use Kiri\Server\Contract\OnTaskInterface;
use Swoole\Server; use Swoole\Server;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Server; namespace Kiri\Server;
trait TraitServer trait TraitServer
{ {
+1 -1
View File
@@ -19,7 +19,7 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Server\\": "./" "Kiri\\Server\\": "./"
} }
} }
} }