DooPHP - fastest MVC based PHP framework

Learn More

The Official Blog of DooPHP

News, Updates, Tips & Tricks for DooPHP

Subscribe to Blog

Subscribe to the official blog of DooPHP framework.

Database Replication (Master-slave) Support in DooPHP2009-08-21 03:41:25

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('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']);

Published under: Tips & Tricks Share/Save/Bookmark

0 Comments:

Be the first to comment. :)

Leave a Reply

About

Categories

Archives


Syndication