PHP code example of moln / swoole-doctrine-pool

1. Go to this page and download the library: Download moln/swoole-doctrine-pool library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

moln / swoole-doctrine-pool example snippets


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;
   }
}