php读写分离事务,分布式,读写分离,多主从,开启事务,代码有问题?

/**

* 连接分布式服务器

* @access protected

* @param boolean $master 主服务器

* @return PDO

*/

protected function multiConnect($master = false)

{

$_config = [];

// 分布式数据库配置解析

foreach (['username', 'password', 'hostname', 'hostport', 'database', 'dsn', 'charset'] as $name) {

$_config[$name] = explode(',', $this->config[$name]);

}

// 主服务器序号

$m = floor(mt_rand(0, $this->config['master_num'] - 1));

if ($this->config['rw_separate']) {

// 主从式采用读写分离

if ($master) // 主服务器写入

{

$r = $m;

} elseif (is_numeric($this->config['slave_no'])) {

// 指定服务器读

$r = $this->config['slave_no'];

} else {

// 读操作连接从服务器 每次随机连接的数据库

$r = floor(mt_rand($this->config['master_num'], count($_config['hostname']) - 1));

}

} else {

// 读写操作不区分服务器 每次随机连接的数据库

$r = floor(mt_rand(0, count($_config['hostname']) - 1));

}

$dbMaster = false;

if ($m != $r) {

$dbMaster = [];

foreach (['username', 'password', 'hostname', 'hostport', 'database', 'dsn', 'charset'] as $name) {

$dbMaster[$name] = isset($_config[$name][$m]) ? $_config[$name][$m] : $_config[$name][0];

}

}

$dbConfig = [];

foreach (['username', 'password', 'hostname', 'hostport', 'database', 'dsn', 'charset'] as $name) {

$dbConfig[$name] = isset($_config[$name][$r]) ? $_config[$name][$r] : $_config[$name][0];

}

return $this->connect($dbConfig, $r, $r == $m ? false : $dbMaster);

}