mirror of
https://github.com/danog/postgres.git
synced 2024-11-27 04:24:45 +01:00
55 lines
1.2 KiB
PHP
55 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Amp\Postgres;
|
|
|
|
use AsyncInterop\Promise;
|
|
|
|
class ConnectionPool extends AbstractPool {
|
|
const DEFAULT_MAX_CONNECTIONS = 100;
|
|
const DEFAULT_CONNECT_TIMEOUT = 5000;
|
|
|
|
/** @var string */
|
|
private $connectionString;
|
|
|
|
/** @var int */
|
|
private $connectTimeout;
|
|
|
|
/** @var int */
|
|
private $maxConnections;
|
|
|
|
/**
|
|
* @param string $connectionString
|
|
* @param int $maxConnections
|
|
* @param int $connectTimeout
|
|
*/
|
|
public function __construct(
|
|
string $connectionString,
|
|
int $maxConnections = self::DEFAULT_MAX_CONNECTIONS,
|
|
int $connectTimeout = self::DEFAULT_CONNECT_TIMEOUT
|
|
) {
|
|
parent::__construct();
|
|
|
|
$this->connectionString = $connectionString;
|
|
$this->connectTimeout = $connectTimeout;
|
|
|
|
$this->maxConnections = $maxConnections;
|
|
if (1 > $this->maxConnections) {
|
|
$this->maxConnections = 1;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function createConnection(): Promise {
|
|
return connect($this->connectionString, $this->connectTimeout);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getMaxConnections(): int {
|
|
return $this->maxConnections;
|
|
}
|
|
}
|