Pool initializes and returns database connections.

package Sporcle
subpackage DBPool
author Dan Munro

 Methods

Returns The number of servers available to connect to for a given instance type.

getConnectionPoolSize(int $instanceType) : int

Parameters

$instanceType

int

The type of database connection to get the pool size for.

Returns

intthe number of available connections

Returns The number of servers available to connect to for a given instance type.

getPoolSize(int $instanceType) : int

access private

Parameters

$instanceType

int

The type of database connection to get the pool size for.

Returns

intthe number of available connections

Use this method to request database connections of the given $instanceType.

instance(int $instanceType) : \Sporcle\DB\mysqli

Parameters

$instanceType

int

The type of database requested

Returns

\Sporcle\DB\mysqliA mysqli connection

Force an open database connection to close.

invalidate(int $instanceType) 

Parameters

$instanceType

int

the type of database to force closed.

Can be used if it is somehow preferable to close an active connection and reconnect to another random server from the pool with the same given instance type.

manualConnectionFailover(int $instanceType) : \Sporcle\DB\Mysqli

Parameters

$instanceType

int

the type of database to force cycling the connection.

Returns

\Sporcle\DB\MysqliA newly opened connection to the database type requested.

If needed, a new connection will be instantiated to the given db type, and the connection will be returned.

requestConnection(int $instanceType) : \Sporcle\DB\Mysqli

access private

Parameters

$instanceType

int

The type of database requested.

Returns

\Sporcle\DB\MysqliAn open database connection.

Initializes DBPool with its pool of connection parameters.

__construct() 

access private

Opens a new connection of the requested instance type if a server remains available from the pool.

establishConnection(int $instanceType) : \Sporcle\DB\Mysqli

Each request for a new connection will remove the parameters for that connection from the pool to prevent reconnecting to the same server (a disconnect/new connection should mean the original connection is no longer accessible or purposely cycled).

access private

Parameters

$instanceType

int

The type of database requested.

Returns

\Sporcle\DB\MysqliAn open database connection.

 Properties

 

<p>represents a pool of available connections, with the first level reserved for the instance type and the second level for associative arrays defining the connection parameters for the given type.</p>

$connectionParams : array

 

<p>holds up to one active connection for each instance type requested. For a given instance, it will only cycle a new connection if the first attempt fails or if requested through manualConnectionFailover().</p>

$connections : array

 

<p>is the single instance of DBPool.</p>

$instance : \Sporcle\DB\DBPool

 Constants

 

CRON

CRON 

 

MASTER

MASTER 

 

SLAVE

SLAVE