Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/db/db_load_balancer.php
Show All 21 Lines | |||||
* @var string | * @var string | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected $dbType = 'mysqli'; | protected $dbType = 'mysqli'; | ||||
/** | /** | ||||
* Function to handle sql errors | * Function to handle sql errors | ||||
* | * | ||||
* @var string | * @var callable | ||||
* @access public | |||||
*/ | */ | ||||
public $errorHandler = ''; | protected $errorHandler = ''; | ||||
/** | /** | ||||
* Database connection settings | * Database connection settings | ||||
* | * | ||||
* @var Array | * @var Array | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected $servers = Array (); | protected $servers = Array (); | ||||
Show All 12 Lines | |||||
* @var Array | * @var Array | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected $serverLagTimes = Array (); | protected $serverLagTimes = Array (); | ||||
/** | /** | ||||
* Connection references to opened connections | * Connection references to opened connections | ||||
* | * | ||||
* @var Array | * @var IDBConnection[] | ||||
* @access protected | |||||
*/ | */ | ||||
protected $connections = Array (); | protected $connections = Array (); | ||||
/** | /** | ||||
* Index of last user slave connection | * Index of last user slave connection | ||||
* | * | ||||
* @var int | * @var int | ||||
* @access protected | * @access protected | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | |||||
* @param string $db_type | * @param string $db_type | ||||
* @param Array|string $error_handler | * @param Array|string $error_handler | ||||
*/ | */ | ||||
function __construct($db_type, $error_handler = '') | function __construct($db_type, $error_handler = '') | ||||
{ | { | ||||
parent::__construct(); | parent::__construct(); | ||||
$this->dbType = $db_type; | $this->dbType = $db_type; | ||||
$this->errorHandler = $error_handler; | $this->setErrorHandler($error_handler); | ||||
$this->DBClusterTimeout *= 1e6; // convert to milliseconds | $this->DBClusterTimeout *= 1e6; // convert to milliseconds | ||||
} | } | ||||
/** | /** | ||||
* Setups load balancer according given configuration. | * Setups load balancer according given configuration. | ||||
* | * | ||||
* @param Array $config | * @param Array $config | ||||
▲ Show 20 Lines • Show All 732 Lines • ▼ Show 20 Line(s) | |||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function getSlaveLag() | public function getSlaveLag() | ||||
{ | { | ||||
$conn =& $this->openConnection($this->lastUsedIndex); | $conn =& $this->openConnection($this->lastUsedIndex); | ||||
return $conn->getSlaveLag(); | return $conn->getSlaveLag(); | ||||
} | } | ||||
/** | |||||
* Sets an error handler. | |||||
* | |||||
* @param callable $error_handler Error handler. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function setErrorHandler(callable $error_handler) | |||||
{ | |||||
$this->errorHandler = $error_handler; | |||||
foreach ( $this->connections as $connection ) { | |||||
$connection->setErrorHandler($error_handler); | |||||
} | |||||
} | |||||
} | } |