fix(realtime): memory leak #2
This commit is contained in:
parent
7a446cf14e
commit
a2315821ca
|
@ -102,9 +102,7 @@ $server->onStart(function () use ($stats, $register, $containerId, &$documentId)
|
|||
/**
|
||||
* Save current connections to the Database every 5 seconds.
|
||||
*/
|
||||
Timer::tick(5000, function () use ($stats, $getConsoleDb, $containerId, &$documentId) {
|
||||
[$consoleDb, $returnConsoleDb] = call_user_func($getConsoleDb);
|
||||
|
||||
Timer::tick(100, function () use ($stats, $getConsoleDb, $containerId, &$documentId) {
|
||||
foreach ($stats as $projectId => $value) {
|
||||
if (empty($value['connections']) && empty($value['messages'])) {
|
||||
continue;
|
||||
|
@ -129,8 +127,6 @@ $server->onStart(function () use ($stats, $register, $containerId, &$documentId)
|
|||
if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') {
|
||||
$usage->trigger();
|
||||
}
|
||||
|
||||
unset($usage, $connections, $messages);
|
||||
}
|
||||
$payload = [];
|
||||
foreach ($stats as $projectId => $value) {
|
||||
|
@ -141,19 +137,21 @@ $server->onStart(function () use ($stats, $register, $containerId, &$documentId)
|
|||
if (empty($payload)) {
|
||||
return;
|
||||
}
|
||||
$document = [
|
||||
'$id' => $documentId,
|
||||
'$collection' => Database::SYSTEM_COLLECTION_CONNECTIONS,
|
||||
'$permissions' => [
|
||||
'read' => ['*'],
|
||||
'write' => ['*'],
|
||||
],
|
||||
'container' => $containerId,
|
||||
'timestamp' => time(),
|
||||
'value' => json_encode($payload)
|
||||
];
|
||||
|
||||
try {
|
||||
$document = $consoleDb->updateDocument($document);
|
||||
[$consoleDb, $returnConsoleDb] = call_user_func($getConsoleDb);
|
||||
|
||||
$consoleDb->updateDocument([
|
||||
'$id' => $documentId,
|
||||
'$collection' => Database::SYSTEM_COLLECTION_CONNECTIONS,
|
||||
'$permissions' => [
|
||||
'read' => ['*'],
|
||||
'write' => ['*'],
|
||||
],
|
||||
'container' => $containerId,
|
||||
'timestamp' => time(),
|
||||
'value' => json_encode($payload)
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
Console::error('[Error] Type: ' . get_class($th));
|
||||
Console::error('[Error] Message: ' . $th->getMessage());
|
||||
|
@ -171,7 +169,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats,
|
|||
$attempts = 0;
|
||||
$start = time();
|
||||
|
||||
Timer::tick(5000, function () use ($server, $register, $realtime, $stats) {
|
||||
Timer::tick(100, function () use ($server, $register, $realtime, $stats) {
|
||||
/**
|
||||
* Sending current connections to project channels on the console project every 5 seconds.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue