diff --git a/src/Console/StartWebSocketServer.php b/src/Console/StartWebSocketServer.php index 26275bb..f26ad31 100644 --- a/src/Console/StartWebSocketServer.php +++ b/src/Console/StartWebSocketServer.php @@ -58,7 +58,8 @@ class StartWebSocketServer extends Command return new HttpStatisticsLogger(app(ChannelManager::class), $client); }); - $this->loop->addPeriodicTimer(60, function() { + $this->loop->addPeriodicTimer(5, function() { + echo 'saving stats...'; StatisticsLogger::save($this->loop); }); diff --git a/src/Statistics/Http/Controllers/WebsocketStatisticsEntriesController.php b/src/Statistics/Http/Controllers/WebsocketStatisticsEntriesController.php index cb2d577..3f38d45 100644 --- a/src/Statistics/Http/Controllers/WebsocketStatisticsEntriesController.php +++ b/src/Statistics/Http/Controllers/WebsocketStatisticsEntriesController.php @@ -3,7 +3,6 @@ namespace BeyondCode\LaravelWebSockets\Statistics\Http\Controllers; use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId; -use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry; use Illuminate\Http\Request; class WebsocketStatisticsEntriesController diff --git a/src/Statistics/Logger/HttpStatisticsLogger.php b/src/Statistics/Logger/HttpStatisticsLogger.php index c268991..731b733 100644 --- a/src/Statistics/Logger/HttpStatisticsLogger.php +++ b/src/Statistics/Logger/HttpStatisticsLogger.php @@ -60,15 +60,27 @@ class HttpStatisticsLogger implements StatisticsLogger public function save() { + echo 'in actual save method'; + foreach ($this->statistics as $appId => $statistic) { - if (! $statistic->isEnabled()) { + echo "stats of ${appId} " . $statistic->isEnabled() ? 'enabled' : 'DISABLED!'; + if (!$statistic->isEnabled()) { continue; } - $this->client->postAsync( - action([WebsocketStatisticsEntriesController::class, 'store']), - $statistic->toArray() - ); + echo 'posted'; + $this->client + ->postAsync( + action([WebsocketStatisticsEntriesController::class, 'store']), + $statistic->toArray() + ) + ->then(function() { + echo 'fulfilled'; + }) + ->otherwise(function() { + echo 'rejected!'; + var_dump(func_get_args()); + }); // Reset connection and message count $currentConnectionCount = collect($this->channelManager->getChannels($appId))