Skip to content

Commit

Permalink
Prevent blocking stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
l3aro committed May 13, 2024
1 parent f0cee42 commit dbe2f3f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
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

0 comments on commit dbe2f3f

Please sign in to comment.