From bbcb943daabfbfe46dd4edd16cfba40a77f9f229 Mon Sep 17 00:00:00 2001 From: a6a2f5842 Date: Thu, 8 May 2025 17:50:05 +0200 Subject: [PATCH] A added timeout information --- src/Websocket/Handler.php | 4 +++- src/Websocket/MockConnection.php | 20 +++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Websocket/Handler.php b/src/Websocket/Handler.php index 3281a18..5671602 100644 --- a/src/Websocket/Handler.php +++ b/src/Websocket/Handler.php @@ -470,10 +470,11 @@ class Handler implements MessageComponentInterface ) { $pidcache_data = 'dedicated_data_'.$pid; $pidcache_done = 'dedicated_data_'.$pid.'_done'; + $pidcache_complete = 'dedicated_data_'.$pid.'_complete'; if ( cache()->has($pidcache_start) - && ($diff = microtime(true) - ((int) cache()->get($pidcache_start))) > 20 + && ($diff = microtime(true) - ((int) cache()->get($pidcache_start))) > 60 ) { if (! $optional) { $connection->send(json_encode([ @@ -486,6 +487,7 @@ class Handler implements MessageComponentInterface } $this->channelManager->loop->cancelTimer($timer); + cache()->put($pidcache_complete, true, 360); } if (cache()->has($pidcache_done)) { diff --git a/src/Websocket/MockConnection.php b/src/Websocket/MockConnection.php index 3168d73..70ac227 100644 --- a/src/Websocket/MockConnection.php +++ b/src/Websocket/MockConnection.php @@ -50,6 +50,13 @@ class MockConnection extends Connection implements \Ratchet\ConnectionInterface public function send($data) { + if(cache()->get('dedicated_data_'.$pid.'_complete')){ + Log::error('[MockConnection] Send for pid: ' . getmypid() . ' which is already completed and does not check for new data', [ + 'data' => $data, + ]); + return false; + } + Log::channel('websocket')->info('[MockConnection] Send for pid: ' . getmypid(), [ 'data' => $data, ]); @@ -59,19 +66,6 @@ class MockConnection extends Connection implements \Ratchet\ConnectionInterface cache()->put($key, $data, 60); cache()->put($key . '_done', true, 60); - // ==== Alternative way without using cache - // if (is_string($data)) { - // $d = json_decode($data, true); - - // \App\Events\TenantEvent::dispatch( - // optional(optional(tenant())->tenantable)->public_id, - // $d['event'], - // (is_array($d['data'])) - // ? $d['data'] - // : ['data' => $d['data']] - // ); - // } - return $this; }