codercms/laravel-pg-conn-pool

Laravel PostgreSQL 连接池

v1.0.2 2020-09-10 17:18 UTC

This package is auto-updated.

Last update: 2024-09-11 03:08:53 UTC


README

Laravel PostgreSQL 连接池

警告:该包尚未准备好投入生产环境(仅用于测试目的)。

原因

  1. 提高应用程序的性能

要求

  1. PHP 7.4
  2. Laravel 6.x
  3. Swoole 4.x 及以上版本
  4. ext-pq 扩展

使用方法

配置(《config/database.php》)

'pgsql_pool' => [
    // driver name that supports connection pooling
    'driver' => 'pgsql_pool',

    // how much connections is needed
    'max_active' => 4,
    // minimum number of active connections
    'min_active' => 2,
    // how much time to wait for an avaiable connection
    'max_wait_time' => 5.0, // 5 seconds
    // automatically close connections which are idle more than a minute
    'max_idle_time' => 60,
    // how often to check idle connections
    'validation_interval' => 30.0, // every 30 seconds
     
    // for more paremeters read the - https://github.com/makise-co/pool
    // parameter names in the connection config should be in snake_case

    // default postgres driver config directives below
    'url' => env('DATABASE_URL'),
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '5432'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'charset' => 'utf8',
    'prefix' => '',
    'prefix_indexes' => true,
    'schema' => 'public',
    'sslmode' => 'prefer',
],

注意

  • LazyConnection 上的以下方法可能无法正常工作(因为它们依赖于真实连接)
    • setPdo
    • setReadPdo
    • disconnect
    • reconnect
  • 所有连接管理都由连接池执行,而不是由 Laravel 执行
  • 每个协程只能从池中获取一个连接