Skip to content

Commit

Permalink
Stop server if something happen to server
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanaelytj committed Oct 31, 2024
1 parent 191ce76 commit 682f413
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Servers/Reverb/Http/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Symfony\Component\HttpKernel\Exception\HttpException;
use Throwable;

use function React\Promise\set_rejection_handler;

class Server
{
use ClosesConnections;
Expand All @@ -38,6 +40,17 @@ public function __construct(protected ServerInterface $socket, protected Router
*/
public function start(): void
{
/** Set global promise rejection handler */
set_rejection_handler(function (Throwable $e) {
Log::error($e->getMessage());

/** Echo error message */
echo "Unhandled exception: {$e->getMessage()}\n Server will stop.\n";

/** Stop the server */
$this->stop();
});

$this->loop->run();
}

Expand Down

0 comments on commit 682f413

Please sign in to comment.