1
0
mirror of https://github.com/danog/postgres.git synced 2024-11-27 04:24:45 +01:00
postgres/lib/ConnectionPool.php

55 lines
1.2 KiB
PHP
Raw Normal View History

2016-12-30 06:21:17 +01:00
<?php
2016-09-14 16:27:39 +02:00
namespace Amp\Postgres;
use Amp\Promise;
2016-09-14 16:27:39 +02:00
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}
*/
2016-11-15 18:06:21 +01:00
protected function createConnection(): Promise {
2016-09-14 16:27:39 +02:00
return connect($this->connectionString, $this->connectTimeout);
}
/**
* {@inheritdoc}
*/
public function getMaxConnections(): int {
return $this->maxConnections;
}
}