diff --git a/src/Appwrite/Database/Pool.php b/src/Appwrite/Database/Pool.php index f914f38e77..ee8902d3d6 100644 --- a/src/Appwrite/Database/Pool.php +++ b/src/Appwrite/Database/Pool.php @@ -1,10 +1,12 @@ pool = new SplQueue; - $this->size = $size; + $this->pool = new Channel($this->size = $size); for ($i = 0; $i < $this->size; $i++) { $pdo = new PDO( "mysql:" . @@ -29,19 +28,19 @@ class PDOPool extends Pool PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true ] ); - $this->pool->enqueue($pdo); + $this->pool->push($pdo); } } public function put(PDO $pdo) { - $this->pool->enqueue($pdo); + $this->pool->push($pdo); } public function get(): PDO { - if ($this->available && count($this->pool) > 0) { - return $this->pool->dequeue(); + if ($this->available && !$this->pool->isEmpty()) { + return $this->pool->pop(); } sleep(0.01); return $this->get(); diff --git a/src/Appwrite/Database/Pool/RedisPool.php b/src/Appwrite/Database/Pool/RedisPool.php index 08e102abb0..47e740b396 100644 --- a/src/Appwrite/Database/Pool/RedisPool.php +++ b/src/Appwrite/Database/Pool/RedisPool.php @@ -3,16 +3,14 @@ namespace Appwrite\Database\Pool; use Appwrite\Database\Pool; -use SplQueue; - use Redis; +use Swoole\Coroutine\Channel; class RedisPool extends Pool { public function __construct(int $size, string $host, int $port, array $auth = []) { - $this->pool = new SplQueue; - $this->size = $size; + $this->pool = new Channel($this->size = $size); for ($i = 0; $i < $this->size; $i++) { $redis = new Redis(); $redis->pconnect($host, $port); @@ -22,19 +20,19 @@ class RedisPool extends Pool $redis->auth($auth); } - $this->pool->enqueue($redis); + $this->pool->push($redis); } } public function put(Redis $redis) { - $this->pool->enqueue($redis); + $this->pool->push($redis); } public function get(): Redis { if ($this->available && !$this->pool->isEmpty()) { - return $this->pool->dequeue(); + return $this->pool->pop(); } sleep(0.1); return $this->get();