Database Replication (Master-slave) Support in DooPHP

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(‘’, ‘’, ‘’);

//OR …
//slave with different info, use a string if it’s same as the master info.
$dbconfig[‘slave’] =
array(‘’, ‘db’, ‘dairy’, ‘668dj0’, ‘mysql’,true),
array(‘’, ‘db’, ‘yuhus’, ‘gu34k2’, ‘mysql’,true),
array(‘’, ‘db’, ‘lily’, ’84ju2a’, ‘mysql’,true),

In index.php just add a line Doo::useDbReplicate() before setting up the DB.

Doo::db()->setDb($dbconfig, $config[‘APP_MODE’]);

Previous PostNextNext Post

Leave a Reply

Your email address will not be published.