x/laravel-connection-pool

此包最新版本(v0.0.1)没有可用的许可证信息。

illuminate/database 连接池

v0.0.1 2019-12-03 07:09 UTC

This package is auto-updated.

Last update: 2024-08-30 01:39:49 UTC


README

Build Status

Laravel 连接池允许你在异步环境中利用 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();