From 520c0652367511850e54a76941d5534fc50ffde0 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 12 Mar 2021 16:56:41 +0100 Subject: [PATCH] move connections back into pool after used --- app/realtime.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/realtime.php b/app/realtime.php index 120117cf3..0483a57fe 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -6,6 +6,8 @@ use Appwrite\Network\Validator\Origin; use Appwrite\Realtime\Realtime; use Appwrite\Utopia\Response; use Swoole\Database\PDOProxy; +use Swoole\Database\RedisConfig; +use Swoole\Database\RedisPool; use Swoole\Process; use Swoole\Http\Request; use Swoole\Http\Response as SwooleResponse; @@ -206,6 +208,21 @@ $server->on('open', function (Server $server, Request $request) use (&$connectio Realtime::subscribe($project->getId(), $connection, $roles, $subscriptions, $connections, $channels); $server->push($connection, json_encode($channels)); + + /** + * Put used PDO and Redis Connections back into their pools. + */ + + /** @var Swoole\Database\PDOPool $dbPool */ + $dbPool = $register->get('dbPool'); + $dbPool->put(new PDOProxy(function () use ($register) { + return $register->get('db'); + } + )); + + /** @var Swoole\Database\RedisPool $redisPool */ + $redisPool = $register->get('redisPool'); + $redisPool->put($register->get('cache')); } catch (\Throwable $th) { $response = [ 'code' => $th->getCode(),