A friend on Weibo asked me how to configure the master and slave data of mybb. actually, I am not very familiar with Mybb, I have roughly looked at the DB and found that the master and slave nodes can be configured in inc/config. in php, configure $ con fig ['database'] ['read'] ['hostname'] = 'localhost '; $ config ['database'] ['read'] ['username'] = 'root '; $ config ['database'] ['read'] ['password'] = ''; $ config ['database'] ['write'] ['hostname'] = 'localhost '; $ config ['database'] ['write'] ['username'] = 'root '; $ config ['database'] ['write'] ['password'] = ''; // read ['R ad'] [0] ['hostname'] for multiple master nodes can be configured with data. However, in db_mysql.php, I found that the master node is being processed. There is an incompatible code. Currently, I do not want to understand the 175 rows of if (array_key_exists ('hostname', $ connections [$ type]) {$ details = $ connections [$ type]; unset ($ connections); // once unset is set, you can only connect to the first read Database. $ connections [$ type] [] = $ details ;} I did not understand the purpose, so I did not modify it. To implement this function, you only need to reprocess the $ connections array.
Process master/slave code
foreach(array('read', 'write') as $type) { print_r($connections);if(!is_array($connections[$type])) { break; } if(array_key_exists('hostname', $connections[$type])) { $details = $connections[$type]; unset($connections); $connections[$type][] = $details; } // Shuffle the connections shuffle($connections[$type]); // Loop-de-loop foreach($connections[$type] as $single_connection) { $connect_function = "mysql_connect"; if($single_connection['pconnect']) { $connect_function = "mysql_pconnect"; } $link = $type."_link"; $this->get_execution_time(); $this->$link = @$connect_function($single_connection['hostname'], $single_connection['username'], $single_connection['password'], 1); $time_spent = $this->get_execution_time(); $this->query_time += $time_spent; // Successful connection? break down brother! if($this->$link) { $this->connections[] = "[".strtoupper($type)."] {$single_connection['username']}@{$single_connection['hostname']} (Connected in ".number_format($time_spent, 0)."s)"; break; } else { $this->connections[] = "[FAILED] [".strtoupper($type)."] {$single_connection['username']}@{$single_connection['hostname']}"; } } }