PHPackages                             makise-co/pool - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. makise-co/pool

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

makise-co/pool
==============

Swoole Connection Pool

v1.0.4(4y ago)26352MITPHPPHP &gt;=7.4

Since Aug 11Pushed 4y ago1 watchersCompare

[ Source](https://github.com/makise-co/pool)[ Packagist](https://packagist.org/packages/makise-co/pool)[ RSS](/packages/makise-co-pool/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (6)Versions (6)Used By (2)

ConnectionPool
==============

[](#connectionpool)

Connection Pool based on Swoole with balancer feature implementation

Parameters
----------

[](#parameters)

- int `maxActive` (default: 2) - The maximum number of active connections that can be allocated from this pool at the same time
- int `minActive` (default: 0) - The minimum number of established connections that should be kept in the pool at all times
- float `maxWaitTime` (default: 5.0) - The maximum number of seconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception. Zero value (0.0) will disable wait timeout.
- float `validationInterval` (default: 5.0) - The number of seconds to sleep between runs of the idle connection validation/cleaner timer. This value should not be set under 1 second. Zero value will disable validate connections timer.
- int `maxIdleTime` (default: 60) - The minimum amount of time (seconds) a connection may sit idle in the pool before it is eligible for closing. Zero value will disable idle connections freeing.
- int `maxLifeTime` (default: 0) - The maximum amount of time (seconds) a connection may exist in the pool before it is eligible for closing. Zero value will disable expired connections freeing.
- bool `testOnBorrow` (default: true) - The indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another.
- bool `testOnReturn` (default: true) - The indication of whether objects will be validated before being returned to the pool
- bool `resetConnections` (default: false) - Reset the connection to its initial state when it is borrowed from the pool

All of these parameters can be changed at runtime.

API
---

[](#api)

- `init` - Initialize (start) connection pool
- `close` - Close (stop) connection pool
- `getStats` - Get connection pool statistics
- `pop` (default visibility: `protected`) - Borrow connection from pool. May throw `BorrowTimeoutException` when waiting of free connection is timed out (read `maxWaitTime` parameter doc). May throw `PoolIsClosedException` when connection pool is closed.
- `push` (default visibility: `protected`) - Return connection to pool

### Getters

[](#getters)

- `getIdleCount` - Get idle connections count
- `getTotalCount` - Get count of connections created by the pool
- `getMaxActive` - read `maxActive` parameter doc
- `getMinActive` - read `minActive` parameter doc
- `getMaxWaitTime` - read `maxWaitTime` parameter doc
- `getMaxIdleTime` - read `maxIdleTime` parameter doc
- `getMaxLifeTime` - read `maxLifeTime` parameter doc
- `getValidationInterval` - read `validationInterval` parameter doc
- `getTestOnBorrow` - read `testOnBorrow` parameter doc
- `getTestOnReturn` - read `testOnReturn` parameter doc
- `getResetConnections` - read `resetConnections` parameter doc

### Setters

[](#setters)

- `setMaxActive` - read `maxActive` parameter doc
- `setMinActive` - read `minActive` parameter doc
- `setMaxWaitTime` - read `maxWaitTime` parameter doc
- `setMaxIdleTime` - read `maxIdleTime` parameter doc
- `setMaxLifeTime` - read `maxLifeTime` parameter doc
- `setValidationInterval` - read `validationInterval` parameter doc
- `setTestOnBorrow` - read `testOnBorrow` parameter doc
- `setTestOnReturn` - read `testOnReturn` parameter doc
- `setResetConnections` - read `resetConnections` parameter doc

Complete example (HTTP Connection Pool)
---------------------------------------

[](#complete-example-http-connection-pool)

```
