moln/swoole-doctrine-pool

Using doctrine pool for swoole

0.1.1 2024-11-26 10:43 UTC

This package is auto-updated.

Last update: 2024-11-26 10:44:27 UTC


README

Installation

composer require moln/swoole-doctrine-pool

Usage

use Moln\SwooleDoctrinePool\DoctrineDbalPool;

class DemoController {
   public function __construct(private DoctrineDbalPool $pool) {}
   
   public function handle() {
        $result = [];
        $dbPool = $this->pool;
        for ($i = 0; $i < 10; $i++) {
            go(function () use ($dbPool, &$result) {
                $conn = $dbPool->get();
                $result[] = $conn->executeQuery('SELECT now() as "now", sleep(1)')->fetchOne();
                $dbPool->put($conn);
            });
        }
        
        return $result;
   }
}