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())); + } + } }