2Sep/081
[LB] with multiple database server
Load balancing is perhaps one of the trickiest things in building a scalable system. But the problem with load balancing in database traffic can easily solved with this code snippet:
function db_cluster_connect($cluster,$usr,$pw){ //<array>,<string>,<string>
shuffle($cluster); //shuffle the array (list) of available hosts
foreach($cluster as $host){
if($link = mysql_connect($host,$usr,$pw)) return $link;
}
return false;
}
10:31 am on January 6th, 2009
Ein gesundes neues Jahr wünscht ihnen das Lausitzblog!