Project

General

Profile

Feature #55157 » slave.diff

Thomas Löffler, 2014-07-16 12:00

View differences:

t3lib/class.t3lib_db.php
var $explainOutput = 0; // Set this to 1 to get queries explained (devIPmask must match). Set the value to 2 to the same but disregarding the devIPmask. There is an alternative option to enable explain output in the admin panel under "TypoScript", which will produce much nicer output, but only works in FE.
// Default link identifier:
var $link = FALSE;
var $link = FALSE;
var $slaveLink = FALSE;
// Default character set, applies unless character set or collation are explicitely set
var $default_charset = 'utf8';
......
*/
protected $postProcessHookObjects = array();
function getMysqlLink()
{
//$rand = rand(0, (count($GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'])+1));
$rand = rand(0, count($GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler']) );
if ($rand > 0)
{
return $this->createMysqlLink( (--$rand) );
}
else
{
return $this->link;
}
}
function createMysqlLink($nr = 0) {
if (file_exists( $_SERVER["DOCUMENT_ROOT"] . "/" . $GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['dead_file'])) {
return $this->link;
}
// Slave deaktivieren:
if (@$GLOBALS['USE_MASTER_ONLY'] === TRUE) {
return $this->link;
}
if (isset($this->slaveLink[$nr]))
return $this->slaveLink[$nr];
$this->slaveLink[$nr] = @mysql_connect( $GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['typo3_db_host'], $GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['typo3_db_username'], $GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['typo3_db_password']);
if (!$this->slaveLink[$nr])
{
/* create dead lock file */
if (isset($GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['dead_file']) && $GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['dead_file'] != '')
{
$file = fopen($_SERVER["DOCUMENT_ROOT"] . "/" . $GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['dead_file'], "w");
fputs($file, mysql_error());
fclose($file);
}
return $this->link;
}
mysql_select_db($GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['typo3_db'] , $this->slaveLink[$nr]);
$setDBinit = t3lib_div::trimExplode(LF, str_replace("' . LF . '", LF, $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']), TRUE);
foreach ($setDBinit as $v) {
if (mysql_query($v, $this->slaveLink[$nr]) === FALSE) {
t3lib_div::sysLog('Could not initialize DB connection with query "' . $v .
'": ' . mysql_error($this->slaveLink[$nr]),
'Core',
3
);
}
}
return $this->slaveLink[$nr];
}
/************************************
*
......
*/
function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '') {
$query = $this->SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
$res = mysql_query($query, $this->link);
$res = mysql_query($query, $this->getMysqlLink());
if ($this->debugOutput) {
$this->debug('exec_SELECTquery');
    (1-1/1)