From 70f7aa12f3232d3e464c727b9ae1637882556601 Mon Sep 17 00:00:00 2001 From: Md Habibur Rahman Date: Wed, 13 Mar 2024 23:06:14 +0600 Subject: [PATCH] Fix: Resolved errors and added support for windows platform --- .../Reverb/Console/Commands/StartServer.php | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Servers/Reverb/Console/Commands/StartServer.php b/src/Servers/Reverb/Console/Commands/StartServer.php index 01ec2c11..864c251f 100644 --- a/src/Servers/Reverb/Console/Commands/StartServer.php +++ b/src/Servers/Reverb/Console/Commands/StartServer.php @@ -147,13 +147,19 @@ protected function ensurePulseEventsAreCollected(LoopInterface $loop, int $inter */ public function getSubscribedSignals(): array { - return [SIGINT, SIGTERM]; + if (! windows_os()) { + return [SIGINT, SIGTERM, SIGTSTP]; + } + + $this->handleSignalWindows(); + + return []; } /** * Handle the signals sent to the server. */ - public function handleSignal(int $signal, int|false $previousExitCode = 0): int|false + public function handleSignal(int $signal = 0, int|false $previousExitCode = 0): int|false { $this->components->info('Gracefully terminating connections.'); @@ -161,4 +167,15 @@ public function handleSignal(int $signal, int|false $previousExitCode = 0): int| return $previousExitCode; } + + /** + * Handle the signals sent to the server on Windows. + */ + + public function handleSignalWindows(): void + { + if(function_exists('sapi_windows_set_ctrl_handler')) { + sapi_windows_set_ctrl_handler(fn () => exit($this->handleSignal())); + } + } }