Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Prevents blocking event loop #195

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"laravel/prompts": "^0.1.15",
"pusher/pusher-php-server": "^7.2",
"ratchet/rfc6455": "^0.3.1",
"react/async": "^4.2",
"react/promise-timer": "^1.10",
"react/socket": "^1.14",
"symfony/console": "^6.0|^7.0",
Expand All @@ -39,7 +40,6 @@
"pestphp/pest": "^2.0",
"phpstan/phpstan": "^1.10",
"ratchet/pawl": "^0.4.1",
"react/async": "^4.0",
"react/http": "^1.9"
},
"autoload": {
Expand Down
18 changes: 10 additions & 8 deletions src/Servers/Reverb/Console/Commands/StartServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\SignalableCommandInterface;

use function React\Async\async;

#[AsCommand(name: 'reverb:start')]
class StartServer extends Command implements SignalableCommandInterface
{
Expand Down Expand Up @@ -90,10 +92,10 @@ protected function ensureHorizontalScalability(LoopInterface $loop): void
*/
protected function ensureStaleConnectionsAreCleaned(LoopInterface $loop): void
{
$loop->addPeriodicTimer(60, function () {
$loop->addPeriodicTimer(60, async(function () {
PruneStaleConnections::dispatch();
PingInactiveConnections::dispatch();
});
}));
}

/**
Expand All @@ -103,7 +105,7 @@ protected function ensureRestartCommandIsRespected(Server $server, LoopInterface
{
$lastRestart = Cache::get('laravel:reverb:restart');

$loop->addPeriodicTimer(5, function () use ($server, $host, $port, $lastRestart) {
$loop->addPeriodicTimer(5, async(function () use ($server, $host, $port, $lastRestart) {
if ($lastRestart === Cache::get('laravel:reverb:restart')) {
return;
}
Expand All @@ -113,7 +115,7 @@ protected function ensureRestartCommandIsRespected(Server $server, LoopInterface
$server->stop();

$this->components->info("Stopping server on {$host}:{$port}");
});
}));
}

/**
Expand Down Expand Up @@ -141,9 +143,9 @@ protected function ensurePulseEventsAreCollected(LoopInterface $loop, int $inter
return;
}

$loop->addPeriodicTimer($interval, function () {
$loop->addPeriodicTimer($interval, async(function () {
$this->laravel->make(\Laravel\Pulse\Pulse::class)->ingest();
});
}));
}

/**
Expand All @@ -155,9 +157,9 @@ protected function ensureTelescopeEntriesAreCollected(LoopInterface $loop, int $
return;
}

$loop->addPeriodicTimer($interval, function () {
$loop->addPeriodicTimer($interval, async(function () {
\Laravel\Telescope\Telescope::store($this->laravel->make(\Laravel\Telescope\Contracts\EntriesRepository::class));
});
}));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Servers/Reverb/Http/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(protected ServerInterface $socket, protected Router

$this->loop = $loop ?: Loop::get();

$this->loop->addPeriodicTimer(30, fn () => gc_collect_cycles());
$this->loop->addPeriodicTimer(30, \React\Async\async(fn () => gc_collect_cycles()));

// Register __invoke handler for this class to receive new connections...
$socket->on('connection', $this);
Expand Down