troodi/laravel-connection-pool

此软件包最新版本(dev-master)没有可用的许可信息。

illuminate/database 的连接池

dev-master 2022-09-05 11:40 UTC

This package is auto-updated.

Last update: 2024-09-05 16:07:19 UTC


README

Build Status

Laravel Connection Pool 允许您在异步环境中充分利用 Laravel 的 查询构建器Eloquent ORM。通过熟悉的流畅接口执行并发数据库操作,无需担心锁定争用,更不用说使用哪个连接了。

注意:此软件包仍在开发中,不适用于生产环境。

要求

  • PHP 7.4+(仅 CLI)
  • Swoole PHP 扩展

安装

composer require x/laravel-connection-pool

使用

// concurrent operations
go(fn () => Server::where('terminated_at', '<=', now()->subMinutes(5))->delete());

go(function () {
    Session::where('active', true)->get()->each(function ($session) {
        //
    });
});

Swoole\Event::wait();
// run 100 SLEEP(1) queries at once, takes ~1s
for ($i = 0; $i < 100; $i++) {
    go(fn () => DB::statement('SELECT SLEEP(1)'));
}

Swoole\Event::wait();