diff --git a/Abstracts/AsyncServer.php b/Abstracts/AsyncServer.php index 70e45f1..71abe38 100644 --- a/Abstracts/AsyncServer.php +++ b/Abstracts/AsyncServer.php @@ -46,10 +46,7 @@ class AsyncServer implements ServerInterface * @param array $service * @param int $daemon * @return void - * @throws ConfigException - * @throws ContainerExceptionInterface - * @throws NotFindClassException - * @throws NotFoundExceptionInterface + * @throws */ public function initCoreServers(array $service, int $daemon = 0): void { @@ -67,7 +64,7 @@ class AsyncServer implements ServerInterface /** * @return bool - * @throws ReflectionException + * @throws */ public function shutdown(): bool { @@ -83,10 +80,7 @@ class AsyncServer implements ServerInterface * @param SConfig $config * @param int $daemon * @return void - * @throws ConfigException - * @throws ContainerExceptionInterface - * @throws NotFindClassException - * @throws NotFoundExceptionInterface + * @throws */ private function createBaseServer(SConfig $config, int $daemon = 0): void { @@ -106,9 +100,7 @@ class AsyncServer implements ServerInterface * @param $config * @param $daemon * @return void - * @throws ConfigException - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface + * @throws */ private function initServer($match, $config, $daemon): void { @@ -139,8 +131,7 @@ class AsyncServer implements ServerInterface * @param SConfig $config * @param int $daemon * @return array - * @throws Exception - * @throws ConfigException + * @throws */ protected function systemConfig(SConfig $config, int $daemon): array { @@ -158,9 +149,7 @@ class AsyncServer implements ServerInterface /** * @param SConfig $config * @return void - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface - * @throws Exception + * @throws */ public function addListener(SConfig $config): void { @@ -177,8 +166,7 @@ class AsyncServer implements ServerInterface /** * @param SConfig $config * @return void - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface + * @throws */ protected function _listenDump(SConfig $config): void { @@ -220,8 +208,7 @@ class AsyncServer implements ServerInterface * @param Server\Port|Server $base * @param array $events * @return void - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface + * @throws */ private function onEventListen(Server\Port|Server $base, array $events): void { diff --git a/Abstracts/ProcessManager.php b/Abstracts/ProcessManager.php index 8ecaf5e..f01eea8 100644 --- a/Abstracts/ProcessManager.php +++ b/Abstracts/ProcessManager.php @@ -26,29 +26,28 @@ class ProcessManager extends Component public StdoutLogger $logger; - /** @var array */ - private array $_process = []; + /** @var array */ + private array $_process = []; - /** - * @return void - * @throws Exception - */ - public function init(): void - { - on(OnServerBeforeStart::class, [$this, 'OnServerBeforeStart']); - } + /** + * @return void + * @throws Exception + */ + public function init(): void + { + on(OnServerBeforeStart::class, [$this, 'OnServerBeforeStart']); + } /** * @param OnServerBeforeStart $beforeStart * @return void - * @throws ReflectionException */ - public function OnServerBeforeStart(OnServerBeforeStart $beforeStart): void - { - $server = Kiri::getDi()->get(ServerInterface::class); - foreach ($this->_process as $custom) { + public function OnServerBeforeStart(OnServerBeforeStart $beforeStart): void + { + $server = Kiri::getDi()->get(ServerInterface::class); + foreach ($this->_process as $custom) { $server->addProcess(new Process(function (Process $process) use ($custom) { $this->extracted($custom, $process); }, @@ -56,139 +55,139 @@ class ProcessManager extends Component $custom->getPipeType(), $custom->isEnableCoroutine() )); - } - } + } + } - /** - * @return Process[] - */ - public function getProcesses(): array - { - return $this->_process; - } + /** + * @return Process[] + */ + public function getProcesses(): array + { + return $this->_process; + } - /** - * @param string|OnProcessInterface|BaseProcess $custom - * @throws Exception - */ - public function add(string|OnProcessInterface|BaseProcess $custom): void - { - if (is_string($custom)) { - $custom = Kiri::getDi()->get($custom); - } + /** + * @param string|OnProcessInterface|BaseProcess $custom + * @throws + */ + public function add(string|OnProcessInterface|BaseProcess $custom): void + { + if (is_string($custom)) { + $custom = Kiri::getDi()->get($custom); + } - if (isset($this->_process[$custom->getName()])) { - throw new Exception('Process(' . $custom->getName() . ') is exists.'); - } + if (isset($this->_process[$custom->getName()])) { + throw new Exception('Process(' . $custom->getName() . ') is exists.'); + } - $this->_process[$custom->getName()] = $custom; - } + $this->_process[$custom->getName()] = $custom; + } - /** - * @return void - */ - public function shutdown(): void - { - foreach ($this->_process as $process) { - Process::kill($process->pid, 0) && Process::kill($process->pid, 15); - } - } + /** + * @return void + */ + public function shutdown(): void + { + foreach ($this->_process as $process) { + Process::kill($process->pid, 0) && Process::kill($process->pid, 15); + } + } - /** - * @param BaseProcess $customProcess - * @return Closure - */ - public function resolve(BaseProcess $customProcess): Closure - { - return static function (Process $process) use ($customProcess) { - $this->extracted($customProcess, $process); - }; - } + /** + * @param BaseProcess $customProcess + * @return Closure + */ + public function resolve(BaseProcess $customProcess): Closure + { + return static function (Process $process) use ($customProcess) { + $this->extracted($customProcess, $process); + }; + } - /** - * @param string|null $name - * @param string $tag - * @return array|Process|null - */ - public function get(?string $name = null, string $tag = 'default'): array|Process|null - { - $process = $this->_process[$tag] ?? null; - if (empty($process)) { - return null; - } - if (!empty($name)) { - if (!isset($process[$name])) { - return null; - } - return $process[$name]; - } - return null; - } + /** + * @param string|null $name + * @param string $tag + * @return array|Process|null + */ + public function get(?string $name = null, string $tag = 'default'): array|Process|null + { + $process = $this->_process[$tag] ?? null; + if (empty($process)) { + return null; + } + if (!empty($name)) { + if (!isset($process[$name])) { + return null; + } + return $process[$name]; + } + return null; + } - /** - * @return void - */ - public function stop(): void - { - foreach ($this->_process as $process) { - Process::kill($process->pid, 0) && Process::kill($process->pid, 15); - } - } + /** + * @return void + */ + public function stop(): void + { + foreach ($this->_process as $process) { + Process::kill($process->pid, 0) && Process::kill($process->pid, 15); + } + } - /** - * @param array|null $processes - * @return void - * @throws Exception - */ - public function batch(?array $processes): void - { - if (empty($processes)) { - return; - } - foreach ($processes as $process) { - $this->add($process); - } - } + /** + * @param array|null $processes + * @return void + * @throws Exception + */ + public function batch(?array $processes): void + { + if (empty($processes)) { + return; + } + foreach ($processes as $process) { + $this->add($process); + } + } - /** - * @param string $message - * @param string $name - * @return void - */ - public function push(string $name, string $message): void - { - if (!isset($this->_process[$name])) { - return; - } - $process = $this->_process[$name]; - $process->write($message); - } + /** + * @param string $message + * @param string $name + * @return void + */ + public function push(string $name, string $message): void + { + if (!isset($this->_process[$name])) { + return; + } + $process = $this->_process[$name]; + $process->write($message); + } - /** - * @param mixed $custom - * @param Process $process - * @return void - * @throws Kiri\Exception\ConfigException - * @throws ReflectionException - */ - public function extracted(mixed $custom, Process $process): void - { - set_env('environmental', Kiri::PROCESS); - $system = sprintf('[%s].Custom Process', \config('id', 'system-service')); - $this->logger->alert($system . ' ' . $custom->getName() . ' start.'); - if (Kiri::getPlatform()->isLinux()) { - $process->name($system . '[' . $process->pid . '].' . $custom->getName()); - } - $custom->onSigterm()->process($process); - } + /** + * @param mixed $custom + * @param Process $process + * @return void + * @throws Kiri\Exception\ConfigException + * @throws ReflectionException + */ + public function extracted(mixed $custom, Process $process): void + { + set_env('environmental', Kiri::PROCESS); + $system = sprintf('[%s].Custom Process', \config('id', 'system-service')); + $this->logger->alert($system . ' ' . $custom->getName() . ' start.'); + if (Kiri::getPlatform()->isLinux()) { + $process->name($system . '[' . $process->pid . '].' . $custom->getName()); + } + $custom->onSigterm()->process($process); + } } diff --git a/Abstracts/Server.php b/Abstracts/Server.php index a0012db..d7da7bb 100644 --- a/Abstracts/Server.php +++ b/Abstracts/Server.php @@ -4,10 +4,6 @@ namespace Kiri\Server\Abstracts; -use Exception; -use Kiri; - - /** * Class Server * @package Server\Abstracts @@ -15,12 +11,12 @@ use Kiri; abstract class Server { - /** - * Server constructor. - * @throws Exception - */ - public function __construct() - { - } + /** + * Server constructor. + * @throws + */ + public function __construct() + { + } } diff --git a/Abstracts/TraitServer.php b/Abstracts/TraitServer.php index f2ca0ae..526960a 100644 --- a/Abstracts/TraitServer.php +++ b/Abstracts/TraitServer.php @@ -21,7 +21,6 @@ trait TraitServer private array $_process = []; - /** * @var StdoutLogger */ @@ -32,7 +31,7 @@ trait TraitServer /** * @param string|array|BaseProcess $class * @return void - * @throws Exception + * @throws */ public function addProcess(string|array|BaseProcess $class): void { @@ -69,7 +68,7 @@ trait TraitServer /** * @return void - * @throws Exception + * @throws */ public function onSignal(): void { diff --git a/Constant.php b/Constant.php index 79d6595..d3cbf87 100644 --- a/Constant.php +++ b/Constant.php @@ -11,123 +11,123 @@ namespace Kiri\Server; class Constant { - const START = 'Start'; - const SHUTDOWN = 'Shutdown'; - const BEFORE_SHUTDOWN = 'beforeShutdown'; - const WORKER_START = 'WorkerStart'; - const WORKER_STOP = 'WorkerStop'; - const WORKER_EXIT = 'WorkerExit'; - const CONNECT = 'Connect'; - const HANDSHAKE = 'handshake'; - const OPEN = 'open'; - const DISCONNECT = 'disconnect'; - const MESSAGE = 'message'; - const RECEIVE = 'Receive'; - const PACKET = 'Packet'; - const REQUEST = 'request'; - const CLOSE = 'Close'; - const TASK = 'Task'; - const FINISH = 'Finish'; - const PIPE_MESSAGE = 'PipeMessage'; - const WORKER_ERROR = 'WorkerError'; - const MANAGER_START = 'ManagerStart'; - const MANAGER_STOP = 'ManagerStop'; - const BEFORE_RELOAD = 'BeforeReload'; - const AFTER_RELOAD = 'AfterReload'; + const string START = 'Start'; + const string SHUTDOWN = 'Shutdown'; + const string BEFORE_SHUTDOWN = 'beforeShutdown'; + const string WORKER_START = 'WorkerStart'; + const string WORKER_STOP = 'WorkerStop'; + const string WORKER_EXIT = 'WorkerExit'; + const string CONNECT = 'Connect'; + const string HANDSHAKE = 'handshake'; + const string OPEN = 'open'; + const string DISCONNECT = 'disconnect'; + const string MESSAGE = 'message'; + const string RECEIVE = 'Receive'; + const string PACKET = 'Packet'; + const string REQUEST = 'request'; + const string CLOSE = 'Close'; + const string TASK = 'Task'; + const string FINISH = 'Finish'; + const string PIPE_MESSAGE = 'PipeMessage'; + const string WORKER_ERROR = 'WorkerError'; + const string MANAGER_START = 'ManagerStart'; + const string MANAGER_STOP = 'ManagerStop'; + const string BEFORE_RELOAD = 'BeforeReload'; + const string AFTER_RELOAD = 'AfterReload'; - const SERVER_TYPE_HTTP = 'http'; - const SERVER_TYPE_WEBSOCKET = 'ws'; - const SERVER_TYPE_TCP = 'tcp'; - const SERVER_TYPE_UDP = 'udp'; - const SERVER_TYPE_BASE = 'base'; + const string SERVER_TYPE_HTTP = 'http'; + const string SERVER_TYPE_WEBSOCKET = 'ws'; + const string SERVER_TYPE_TCP = 'tcp'; + const string SERVER_TYPE_UDP = 'udp'; + const string SERVER_TYPE_BASE = 'base'; - const STATUS_404_MESSAGE = '

HTTP 404 Not Found


Powered by Swoole'; - const STATUS_405_MESSAGE = '

HTTP 405 Method allow


Powered by Swoole'; + const string STATUS_404_MESSAGE = '

HTTP 404 Not Found


Powered by Swoole'; + const string STATUS_405_MESSAGE = '

HTTP 405 Method allow


Powered by Swoole'; - const OPTION_REACTOR_NUM = 'reactor_num'; - const OPTION_WORKER_NUM = 'worker_num'; - const OPTION_MAX_REQUEST = 'max_request'; - const OPTION_MAX_CONN = 'max_connection'; - const OPTION_TASK_WORKER_NUM = 'task_worker_num'; - const OPTION_TASK_IPC_MODE = 'task_ipc_mode'; - const OPTION_TASK_MAX_REQUEST = 'task_max_request'; - const OPTION_TASK_TMPDIR = 'task_tmpdir'; - const OPTION_TASK_ENABLE_COROUTINE = 'task_enable_coroutine'; - const OPTION_TASK_USE_OBJECT = 'task_use_object'; - const OPTION_DISPATCH_MODE = 'dispatch_mode'; - const OPTION_DISPATCH_FUNC = 'dispatch_func'; - const OPTION_MESSAGE_QUEUE_KEY = 'message_queue_key'; - const OPTION_DAEMONIZE = 'daemonize'; - const OPTION_BACKLOG = 'backlog'; - const OPTION_LOG_FILE = 'log_file'; - const OPTION_LOG_LEVEL = 'log_level'; - const OPTION_LOG_DATE_WITH_MICROSECONDS = 'log_date_with_microseconds'; - const OPTION_LOG_ROTATION = 'log_rotation'; - const OPTION_LOG_DATE_FORMAT = 'log_date_format'; - const OPTION_OPEN_TCP_KEEPALIVE = 'open_tcp_keepalive'; - const OPTION_HEARTBEAT_CHECK_INTERVAL = 'heartbeat_check_interval'; - const OPTION_HEARTBEAT_IDLE_TIME = 'heartbeat_idle_time'; - const OPTION_OPEN_EOF_CHECK = 'open_eof_check'; - const OPTION_OPEN_EOF_SPLIT = 'open_eof_split'; - const OPTION_PACKAGE_EOF = 'package_eof'; - const OPTION_OPEN_LENGTH_CHECK = 'open_length_check'; - const OPTION_PACKAGE_LENGTH_TYPE = 'package_length_type'; - const OPTION_PACKAGE_LENGTH_FUNC = 'package_length_func'; - const OPTION_PACKAGE_MAX_LENGTH = 'package_max_length'; - const OPTION_OPEN_HTTP_PROTOCOL = 'open_http_protocol'; - const OPTION_OPEN_MQTT_PROTOCOL = 'open_mqtt_protocol'; - const OPTION_OPEN_REDIS_PROTOCOL = 'open_redis_protocol'; - const OPTION_OPEN_WEBSOCKET_PROTOCOL = 'open_websocket_protocol'; - const OPTION_OPEN_WEBSOCKET_CLOSE_FRAME = 'open_websocket_close_frame'; - const OPTION_OPEN_TCP_NODELAY = 'open_tcp_nodelay'; - const OPTION_OPEN_CPU_AFFINITY = 'open_cpu_affinity'; - const OPTION_CPU_AFFINITY_IGNORE = 'cpu_affinity_ignore'; - const OPTION_TCP_DEFER_ACCEPT = 'tcp_defer_accept'; - const OPTION_SSL_CERT_FILE = 'ssl_cert_file'; - const OPTION_SSL_KEY_FILE = 'ssl_key_file'; - const OPTION_SSL_METHOD = 'ssl_method'; - const OPTION_SSL_PROTOCOLS = 'ssl_protocols'; - const OPTION_SSL_SNI_CERTS = 'ssl_sni_certs'; - const OPTION_SSL_CIPHERS = 'ssl_ciphers'; - const OPTION_SSL_VERIFY_PEER = 'ssl_verify_peer'; - const OPTION_SSL_ALLOW_SELF_SIGNED = 'ssl_allow_self_signed'; - const OPTION_SSL_CLIENT_CERT_FILE = 'ssl_client_cert_file'; - const OPTION_SSL_COMPRESS = 'ssl_compress'; - const OPTION_SSL_VERIFY_DEPTH = 'ssl_verify_depth'; - const OPTION_SSL_PREFER_SERVER_CIPHERS = 'ssl_prefer_server_ciphers'; - const OPTION_SSL_DHPARAM = 'ssl_dhparam'; - const OPTION_SSL_ECDH_CURVE = 'ssl_ecdh_curve'; - const OPTION_USER = 'user'; - const OPTION_GROUP = 'group'; - const OPTION_CHROOT = 'chroot'; - const OPTION_PID_FILE = 'pid_file'; - const OPTION_BUFFER_INPUT_SIZE = 'buffer_input_size'; - const OPTION_BUFFER_OUTPUT_SIZE = 'buffer_output_size'; - const OPTION_SOCKET_BUFFER_SIZE = 'socket_buffer_size'; - const OPTION_ENABLE_UNSAFE_EVENT = 'enable_unsafe_event'; - const OPTION_DISCARD_TIMEOUT_REQUEST = 'discard_timeout_request'; - const OPTION_ENABLE_REUSE_PORT = 'enable_reuse_port'; - const OPTION_ENABLE_DELAY_RECEIVE = 'enable_delay_receive'; - const OPTION_RELOAD_ASYNC = 'reload_async'; - const OPTION_MAX_WAIT_TIME = 'max_wait_time'; - const OPTION_TCP_FASTOPEN = 'tcp_fastopen'; - const OPTION_REQUEST_SLOWLOG_FILE = 'request_slowlog_file'; - const OPTION_ENABLE_COROUTINE = 'enable_coroutine'; - const OPTION_MAX_COROUTINE = 'max_coroutine'; - const OPTION_SEND_YIELD = 'send_yield'; - const OPTION_SEND_TIMEOUT = 'send_timeout'; - const OPTION_HOOK_FLAGS = 'hook_flags'; - const OPTION_BUFFER_HIGH_WATERMARK = 'buffer_high_watermark'; - const OPTION_BUFFER_LOW_WATERMARK = 'buffer_low_watermark'; - const OPTION_TCP_USER_TIMEOUT = 'tcp_user_timeout'; - const OPTION_STATS_FILE = 'stats_file'; - const OPTION_EVENT_OBJECT = 'event_object'; - const OPTION_START_SESSION_ID = 'start_session_id'; - const OPTION_SINGLE_THREAD = 'single_thread'; - const OPTION_MAX_QUEUED_BYTES = 'max_queued_bytes'; + const string OPTION_REACTOR_NUM = 'reactor_num'; + const string OPTION_WORKER_NUM = 'worker_num'; + const string OPTION_MAX_REQUEST = 'max_request'; + const string OPTION_MAX_CONN = 'max_connection'; + const string OPTION_TASK_WORKER_NUM = 'task_worker_num'; + const string OPTION_TASK_IPC_MODE = 'task_ipc_mode'; + const string OPTION_TASK_MAX_REQUEST = 'task_max_request'; + const string OPTION_TASK_TMPDIR = 'task_tmpdir'; + const string OPTION_TASK_ENABLE_COROUTINE = 'task_enable_coroutine'; + const string OPTION_TASK_USE_OBJECT = 'task_use_object'; + const string OPTION_DISPATCH_MODE = 'dispatch_mode'; + const string OPTION_DISPATCH_FUNC = 'dispatch_func'; + const string OPTION_MESSAGE_QUEUE_KEY = 'message_queue_key'; + const string OPTION_DAEMONIZE = 'daemonize'; + const string OPTION_BACKLOG = 'backlog'; + const string OPTION_LOG_FILE = 'log_file'; + const string OPTION_LOG_LEVEL = 'log_level'; + const string OPTION_LOG_DATE_WITH_MICROSECONDS = 'log_date_with_microseconds'; + const string OPTION_LOG_ROTATION = 'log_rotation'; + const string OPTION_LOG_DATE_FORMAT = 'log_date_format'; + const string OPTION_OPEN_TCP_KEEPALIVE = 'open_tcp_keepalive'; + const string OPTION_HEARTBEAT_CHECK_INTERVAL = 'heartbeat_check_interval'; + const string OPTION_HEARTBEAT_IDLE_TIME = 'heartbeat_idle_time'; + const string OPTION_OPEN_EOF_CHECK = 'open_eof_check'; + const string OPTION_OPEN_EOF_SPLIT = 'open_eof_split'; + const string OPTION_PACKAGE_EOF = 'package_eof'; + const string OPTION_OPEN_LENGTH_CHECK = 'open_length_check'; + const string OPTION_PACKAGE_LENGTH_TYPE = 'package_length_type'; + const string OPTION_PACKAGE_LENGTH_FUNC = 'package_length_func'; + const string OPTION_PACKAGE_MAX_LENGTH = 'package_max_length'; + const string OPTION_OPEN_HTTP_PROTOCOL = 'open_http_protocol'; + const string OPTION_OPEN_MQTT_PROTOCOL = 'open_mqtt_protocol'; + const string OPTION_OPEN_REDIS_PROTOCOL = 'open_redis_protocol'; + const string OPTION_OPEN_WEBSOCKET_PROTOCOL = 'open_websocket_protocol'; + const string OPTION_OPEN_WEBSOCKET_CLOSE_FRAME = 'open_websocket_close_frame'; + const string OPTION_OPEN_TCP_NODELAY = 'open_tcp_nodelay'; + const string OPTION_OPEN_CPU_AFFINITY = 'open_cpu_affinity'; + const string OPTION_CPU_AFFINITY_IGNORE = 'cpu_affinity_ignore'; + const string OPTION_TCP_DEFER_ACCEPT = 'tcp_defer_accept'; + const string OPTION_SSL_CERT_FILE = 'ssl_cert_file'; + const string OPTION_SSL_KEY_FILE = 'ssl_key_file'; + const string OPTION_SSL_METHOD = 'ssl_method'; + const string OPTION_SSL_PROTOCOLS = 'ssl_protocols'; + const string OPTION_SSL_SNI_CERTS = 'ssl_sni_certs'; + const string OPTION_SSL_CIPHERS = 'ssl_ciphers'; + const string OPTION_SSL_VERIFY_PEER = 'ssl_verify_peer'; + const string OPTION_SSL_ALLOW_SELF_SIGNED = 'ssl_allow_self_signed'; + const string OPTION_SSL_CLIENT_CERT_FILE = 'ssl_client_cert_file'; + const string OPTION_SSL_COMPRESS = 'ssl_compress'; + const string OPTION_SSL_VERIFY_DEPTH = 'ssl_verify_depth'; + const string OPTION_SSL_PREFER_SERVER_CIPHERS = 'ssl_prefer_server_ciphers'; + const string OPTION_SSL_DHPARAM = 'ssl_dhparam'; + const string OPTION_SSL_ECDH_CURVE = 'ssl_ecdh_curve'; + const string OPTION_USER = 'user'; + const string OPTION_GROUP = 'group'; + const string OPTION_CHROOT = 'chroot'; + const string OPTION_PID_FILE = 'pid_file'; + const string OPTION_BUFFER_INPUT_SIZE = 'buffer_input_size'; + const string OPTION_BUFFER_OUTPUT_SIZE = 'buffer_output_size'; + const string OPTION_SOCKET_BUFFER_SIZE = 'socket_buffer_size'; + const string OPTION_ENABLE_UNSAFE_EVENT = 'enable_unsafe_event'; + const string OPTION_DISCARD_TIMEOUT_REQUEST = 'discard_timeout_request'; + const string OPTION_ENABLE_REUSE_PORT = 'enable_reuse_port'; + const string OPTION_ENABLE_DELAY_RECEIVE = 'enable_delay_receive'; + const string OPTION_RELOAD_ASYNC = 'reload_async'; + const string OPTION_MAX_WAIT_TIME = 'max_wait_time'; + const string OPTION_TCP_FASTOPEN = 'tcp_fastopen'; + const string OPTION_REQUEST_SLOWLOG_FILE = 'request_slowlog_file'; + const string OPTION_ENABLE_COROUTINE = 'enable_coroutine'; + const string OPTION_MAX_COROUTINE = 'max_coroutine'; + const string OPTION_SEND_YIELD = 'send_yield'; + const string OPTION_SEND_TIMEOUT = 'send_timeout'; + const string OPTION_HOOK_FLAGS = 'hook_flags'; + const string OPTION_BUFFER_HIGH_WATERMARK = 'buffer_high_watermark'; + const string OPTION_BUFFER_LOW_WATERMARK = 'buffer_low_watermark'; + const string OPTION_TCP_USER_TIMEOUT = 'tcp_user_timeout'; + const string OPTION_STATS_FILE = 'stats_file'; + const string OPTION_EVENT_OBJECT = 'event_object'; + const string OPTION_START_SESSION_ID = 'start_session_id'; + const string OPTION_SINGLE_THREAD = 'single_thread'; + const string OPTION_MAX_QUEUED_BYTES = 'max_queued_bytes'; } diff --git a/Handler/OnPipeMessage.php b/Handler/OnPipeMessage.php index 6be23ab..89126f8 100644 --- a/Handler/OnPipeMessage.php +++ b/Handler/OnPipeMessage.php @@ -13,23 +13,22 @@ class OnPipeMessage extends Server { - - /** - * @param \Swoole\Server $server - * @param int $src_worker_id - * @param mixed $message - * @throws Exception - */ - public function onPipeMessage(\Swoole\Server $server, int $src_worker_id, mixed $message): void - { - if (is_string($message)) { - $message = unserialize($message); - } - if (!is_object($message) || !($message instanceof OnPipeMessageInterface)) { - return; - } - call_user_func([$message, 'process'], $server, $src_worker_id); - } + /** + * @param \Swoole\Server $server + * @param int $src_worker_id + * @param mixed $message + * @throws + */ + public function onPipeMessage(\Swoole\Server $server, int $src_worker_id, mixed $message): void + { + if (is_string($message)) { + $message = unserialize($message); + } + if (!is_object($message) || !($message instanceof OnPipeMessageInterface)) { + return; + } + call_user_func([$message, 'process'], $server, $src_worker_id); + } } diff --git a/Handler/OnRequest.php b/Handler/OnRequest.php index d5dc8c4..fbb16c3 100644 --- a/Handler/OnRequest.php +++ b/Handler/OnRequest.php @@ -61,9 +61,7 @@ class OnRequest implements OnRequestInterface * @param ResponseInterface $response * @param ContainerInterface $container * @param DataGrip $dataGrip - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface - * @throws ReflectionException + * @throws */ public function __construct(public ResponseInterface $response, public ContainerInterface $container, public DataGrip $dataGrip) @@ -81,7 +79,7 @@ class OnRequest implements OnRequestInterface /** * @param Request $request * @param Response $response - * @throws Exception + * @throws */ public function onRequest(Request $request, Response $response): void { diff --git a/Handler/OnServer.php b/Handler/OnServer.php index 573cb76..b3971f1 100644 --- a/Handler/OnServer.php +++ b/Handler/OnServer.php @@ -31,7 +31,7 @@ class OnServer extends Server /** * @param SServer $server - * @throws ReflectionException + * @throws */ public function onStart(SServer $server): void { @@ -45,7 +45,7 @@ class OnServer extends Server /** * @param SServer $server - * @throws ReflectionException + * @throws */ public function onBeforeShutdown(SServer $server): void { diff --git a/Handler/OnServerManager.php b/Handler/OnServerManager.php index b2fdf56..22b3711 100644 --- a/Handler/OnServerManager.php +++ b/Handler/OnServerManager.php @@ -17,27 +17,27 @@ class OnServerManager extends Server { - /** - * @param \Swoole\Server $server - * @throws ReflectionException - */ - public function onManagerStart(\Swoole\Server $server): void - { - Kiri::setProcessName(sprintf('manger process[%d]', $server->manager_pid)); + /** + * @param \Swoole\Server $server + * @throws + */ + public function onManagerStart(\Swoole\Server $server): void + { + Kiri::setProcessName(sprintf('manger process[%d]', $server->manager_pid)); - event(new OnManagerStart($server)); - } + event(new OnManagerStart($server)); + } - /** - * @param \Swoole\Server $server - * @return void - * @throws ReflectionException - */ - public function onManagerStop(\Swoole\Server $server): void - { - event(new OnManagerStop($server)); - } + /** + * @param \Swoole\Server $server + * @return void + * @throws + */ + public function onManagerStop(\Swoole\Server $server): void + { + event(new OnManagerStop($server)); + } } diff --git a/Handler/OnServerWorker.php b/Handler/OnServerWorker.php index 8a5c40f..efd8826 100644 --- a/Handler/OnServerWorker.php +++ b/Handler/OnServerWorker.php @@ -64,7 +64,7 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server * @param Server $server * @param int $workerId * @return void - * @throws Exception + * @throws */ public function onWorkerStart(Server $server, int $workerId): void { @@ -92,7 +92,7 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server /** * @param Server $server * @param int $workerId - * @throws ReflectionException + * @throws */ public function onWorkerStop(Server $server, int $workerId): void { @@ -104,7 +104,7 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server /** * @param Server $server * @param int $workerId - * @throws ReflectionException + * @throws */ public function onWorkerExit(Server $server, int $workerId): void { @@ -118,7 +118,7 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server * @param int $worker_pid * @param int $exit_code * @param int $signal - * @throws Exception + * @throws */ public function onWorkerError(Server $server, int $worker_id, int $worker_pid, int $exit_code, int $signal): void { @@ -135,7 +135,7 @@ class OnServerWorker extends \Kiri\Server\Abstracts\Server /** * @param $messageContent - * @throws Exception + * @throws */ protected function system_mail($messageContent): void { diff --git a/HotReload.php b/HotReload.php index bd8fcd5..13df5d4 100644 --- a/HotReload.php +++ b/HotReload.php @@ -68,7 +68,7 @@ class HotReload extends BaseProcess /** * @param $data * @return void - * @throws Exception + * @throws */ public function onStop($data): void { @@ -85,7 +85,7 @@ class HotReload extends BaseProcess /** * @param Process|null $process * @return void - * @throws Exception + * @throws */ public function process(?Process $process): void { @@ -101,7 +101,7 @@ class HotReload extends BaseProcess /** * @return void - * @throws Exception + * @throws */ private function onCrontabReload(): void { @@ -112,7 +112,7 @@ class HotReload extends BaseProcess /** * @return void - * @throws Exception + * @throws */ private function onInotifyReload(): void { @@ -133,7 +133,7 @@ class HotReload extends BaseProcess /** * @param bool $isReload - * @throws Exception + * @throws */ private function loadDirs(bool $isReload = false): void { @@ -150,7 +150,7 @@ class HotReload extends BaseProcess /** - * @throws Exception + * @throws */ public function tick(): void { @@ -176,7 +176,7 @@ class HotReload extends BaseProcess * @param $path * @param bool $isReload * @return void - * @throws Exception + * @throws */ private function loadByDir($path, bool $isReload = false): void { @@ -262,7 +262,7 @@ class HotReload extends BaseProcess } /** - * @throws Exception + * @throws */ public function reload(): void { @@ -278,7 +278,7 @@ class HotReload extends BaseProcess } /** - * @throws Exception + * @throws */ public function timerReload(): void { @@ -297,7 +297,7 @@ class HotReload extends BaseProcess /** * 重启 - * @throws Exception + * @throws */ public function trigger_reload(): void { @@ -307,7 +307,7 @@ class HotReload extends BaseProcess /** - * @throws Exception + * @throws */ public function clearWatch(): void { @@ -325,7 +325,7 @@ class HotReload extends BaseProcess /** * @param $dir * @return bool - * @throws Exception + * @throws */ public function watch($dir): bool { diff --git a/ServerCommand.php b/ServerCommand.php index 789c9ba..a18c86a 100644 --- a/ServerCommand.php +++ b/ServerCommand.php @@ -66,7 +66,7 @@ class ServerCommand extends Command * @param InputInterface $input * @param OutputInterface $output * @return int - * @throws Exception + * @throws */ public function execute(InputInterface $input, OutputInterface $output): int { @@ -83,7 +83,7 @@ class ServerCommand extends Command /** * @param InputInterface $input * @return int - * @throws ReflectionException + * @throws */ protected function restart(InputInterface $input): int { @@ -95,8 +95,7 @@ class ServerCommand extends Command /** * @return int - * @throws ReflectionException - * @throws Exception + * @throws */ protected function stop(): int { diff --git a/ServerProviders.php b/ServerProviders.php index 18a58d0..749c8b3 100644 --- a/ServerProviders.php +++ b/ServerProviders.php @@ -5,8 +5,6 @@ namespace Kiri\Server; use Kiri\Abstracts\Providers; -use Psr\Container\ContainerExceptionInterface; -use Psr\Container\NotFoundExceptionInterface; use Symfony\Component\Console\Application; /** @@ -17,15 +15,14 @@ class ServerProviders extends Providers { - /** - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface - */ - public function onImport(): void - { - $server = $this->container->get(ServerCommand::class); + /** + * @throws + */ + public function onImport(): void + { + $server = $this->container->get(ServerCommand::class); - $console = $this->container->get(Application::class); - $console->add($server); - } + $console = $this->container->get(Application::class); + $console->add($server); + } } diff --git a/State.php b/State.php index d0e77b1..604abc9 100644 --- a/State.php +++ b/State.php @@ -2,7 +2,6 @@ namespace Kiri\Server; -use Exception; use Kiri\Abstracts\Component; use Kiri\Server\Abstracts\TraitServer; use Swoole\Process; @@ -11,50 +10,50 @@ use function config; class State extends Component { - use TraitServer; + use TraitServer; - public array $servers = []; + public array $servers = []; - /** - * @return void - */ - public function init(): void - { - $this->servers = config('server.ports'); - } + /** + * @return void + */ + public function init(): void + { + $this->servers = config('server.ports'); + } - /** - * @return bool - * @throws Exception - */ - public function isRunner(): bool - { - $ports = $this->sortService($this->servers); - foreach ($ports as $config) { - if (checkPortIsAlready($config['port'])) { - return true; - } - } - return false; - } + /** + * @return bool + * @throws + */ + public function isRunner(): bool + { + $ports = $this->sortService($this->servers); + foreach ($ports as $config) { + if (checkPortIsAlready($config['port'])) { + return true; + } + } + return false; + } - /** - * @param $port - * @throws Exception - */ - public function exit($port): void - { - if (!($pid = checkPortIsAlready($port))) { - return; - } - while (checkPortIsAlready($port)) { - Process::kill($pid, 0) && Process::kill($pid, SIGTERM); - usleep(300); - } - } + /** + * @param $port + * @throws + */ + public function exit($port): void + { + if (!($pid = checkPortIsAlready($port))) { + return; + } + while (checkPortIsAlready($port)) { + Process::kill($pid, 0) && Process::kill($pid, SIGTERM); + usleep(300); + } + } } diff --git a/Task/Task.php b/Task/Task.php index 00d9496..dd1c97f 100644 --- a/Task/Task.php +++ b/Task/Task.php @@ -3,10 +3,8 @@ namespace Kiri\Server\Task; -use Exception; use Kiri; use Kiri\Server\Constant; -use ReflectionException; use Swoole\Server; /** @@ -37,7 +35,7 @@ class Task * @param int $task_id * @param mixed $data * @return void - * @throws ReflectionException + * @throws */ public function onFinish(Server $server, int $task_id, mixed $data): void { @@ -51,7 +49,7 @@ class Task * @param int $src_worker_id * @param mixed $data * @return mixed - * @throws ReflectionException|Exception + * @throws */ public function onTask(Server $server, int $task_id, int $src_worker_id, mixed $data): mixed {