承接 diego-ninja/swoole-mysql-doctrine-driver 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

diego-ninja/swoole-mysql-doctrine-driver

Composer 安装命令:

composer require diego-ninja/swoole-mysql-doctrine-driver

包简介

A Doctrine DBAL Driver implementation on top of Swoole Coroutine Mysql extension

README 文档

README

A Doctrine\DBAL\Driver implementation on top of Swoole\Coroutine\MySQL.

Getting started

Install

composer require diego-ninja/swoole-mysql-doctrine-driver

Usage

Doctrine parameters, for both DBAL and ORM projects, accepts the driverClass option; it is where we can inject this project's driver:

use Doctrine\DBAL\{Driver, DriverManager};

$params = [
    'dbname' => 'mysql',
    'user' => 'mysql',
    'password' => 'mysql',
    'host' => 'db',
    'driverClass' => Driver\Swoole\Coroutine\Mysql\Driver::class,
    'poolSize' => 8,
];

$conn = DriverManager::getConnection($params);

Yes, I deliberately used the Doctrine\DBAL\Driver namespace + Swoole\Coroutine\MySQL namespace, so it is not confusing.

You are ready to rock inside Coroutines (Fibers):

Co\run(static function() use ($conn): void {
    $results = [];
    $wg = new Co\WaitGroup();
    $start_time = time();

    Co::create(static function() use (&$results, $wg, $conn): void {
        $wg->add();
        $results[] = $conn->executeQuery('select 1, sleep(1)')->fetchOne();
        $wg->done();
    });

    Co::create(static function() use (&$results, $wg, $conn): void {
        $wg->add();
        $results[] = $conn->executeQuery('select 1, sleep(1)')->fetchOne();
        $wg->done();
    });

    $wg->wait();
    $elapsed = time() - $start_time;
    $sum = array_sum($results);

    echo "Two sleep(1) queries in $elapsed second, returning: $sum\n";
});

You should be seeing Two sleep(1) queries in 1 second, returning: 2 and the total time should not be 2 (the sum of sleep(1)'s) because they ran concurrently.

real    0m1.228s
user    0m0.036s
sys     0m0.027s

统计信息

  • 总下载量: 121
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 0
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-31