Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 3123f25

Browse files
committed
Renamed HttpStatisticsLogger with MemoryStatisticsLogger (because it stores it in-memory)
1 parent 850ebe5 commit 3123f25

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

config/websockets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
|
213213
*/
214214

215-
'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger::class,
215+
'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class,
216216
// 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\NullStatisticsLogger::class,
217217

218218
/*

docs/debugging/dashboard.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ However, to disable it entirely and void any incoming statistic, you can uncomme
8888
|
8989
*/
9090

91-
// 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger::class,
91+
// 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class,
9292
'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\NullStatisticsLogger::class, // use the `NullStatisticsLogger` instead
9393
```
9494

src/Console/StartWebSocketServer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class StartWebSocketServer extends Command
3333
protected $signature = 'websockets:serve
3434
{--host=0.0.0.0}
3535
{--port=6001}
36+
{--statistics-interval= : Overwrite the statistics interval set in the config.}
3637
{--debug : Forces the loggers to be enabled and thereby overriding the APP_DEBUG setting.}
3738
{--test : Prepare the server, but do not start it.}
3839
';
@@ -110,15 +111,17 @@ protected function configureStatisticsLogger()
110111
$browser = new Browser($this->loop, $connector);
111112

112113
$this->laravel->singleton(StatisticsLoggerInterface::class, function () use ($browser) {
113-
$class = config('websockets.statistics.logger', \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger::class);
114+
$class = config('websockets.statistics.logger', \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class);
114115

115116
return new $class(
116117
$this->laravel->make(ChannelManager::class),
117118
$browser
118119
);
119120
});
120121

121-
$this->loop->addPeriodicTimer(config('websockets.statistics.interval_in_seconds'), function () {
122+
$this->loop->addPeriodicTimer($this->option('statistics-interval') ?: config('websockets.statistics.interval_in_seconds'), function () {
123+
$this->line('Saving statistics...');
124+
122125
StatisticsLogger::save();
123126
});
124127

src/Facades/StatisticsLogger.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Illuminate\Support\Facades\Facade;
77

88
/**
9-
* @see \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger
10-
* @mixin \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger
9+
* @see \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger
10+
* @mixin \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger
1111
*/
1212
class StatisticsLogger extends Facade
1313
{

src/Statistics/Logger/HttpStatisticsLogger.php renamed to src/Statistics/Logger/MemoryStatisticsLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use function GuzzleHttp\Psr7\stream_for;
1111
use Ratchet\ConnectionInterface;
1212

13-
class HttpStatisticsLogger implements StatisticsLogger
13+
class MemoryStatisticsLogger implements StatisticsLogger
1414
{
1515
/**
1616
* The list of stored statistics.

tests/Statistics/Logger/FakeStatisticsLogger.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
namespace BeyondCode\LaravelWebSockets\Tests\Statistics\Logger;
44

5-
use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger;
5+
use BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger;
66

7-
class FakeStatisticsLogger extends HttpStatisticsLogger
7+
class FakeStatisticsLogger extends MemoryStatisticsLogger
88
{
9+
/**
10+
* {@inheritdoc}
11+
*/
912
public function save()
1013
{
1114
foreach ($this->statistics as $appId => $statistic) {
@@ -14,6 +17,12 @@ public function save()
1417
}
1518
}
1619

20+
/**
21+
* Get app by id.
22+
*
23+
* @param mixed $appId
24+
* @return array
25+
*/
1726
public function getForAppId($appId): array
1827
{
1928
$statistic = $this->findOrMakeStatisticForAppId($appId);

0 commit comments

Comments
 (0)