Database replication support is added in DooPHP.
Most simple frameworks/application have no separation of Reads and Writes of the DB. Once the projects outgrow a single server RDBMS the next step is often to do a Master/Slave setup in MySQL.
In a Master/Slave setup expensive and less frequent writes are channeled to the Master server while reads are channelled to the Slave server.
In DooPHP, we simplifies thing to merely just define the Slave server configurations in db.conf.php
You need to call Doo::useDbReplicate() in the bootstrap index.php, and that’s all!
The query stuffs remain the same.
To setup:
//This will serve as the Master
$dbconfig[‘dev’] = array(‘localhost’, ‘db’, ‘root’, ‘1234’, ‘mysql’,true);
//slave with the same info as master
$dbconfig[‘slave’] = array(‘192.168.1.1’, ‘192.168.1.2’, ‘192.168.1.3’);
//OR …
//slave with different info, use a string if it’s same as the master info.
$dbconfig[‘slave’] =
array(
array(‘192.168.1.1’, ‘db’, ‘dairy’, ‘668dj0’, ‘mysql’,true),
array(‘192.168.1.2’, ‘db’, ‘yuhus’, ‘gu34k2’, ‘mysql’,true),
array(‘192.168.1.3’, ‘db’, ‘lily’, ’84ju2a’, ‘mysql’,true),
‘192.168.1.4’
);
In index.php just add a line Doo::useDbReplicate() before setting up the DB.
Doo::useDbReplicate();
Doo::db()->setMap($dbmap);
Doo::db()->setDb($dbconfig, $config[‘APP_MODE’]);