How to Cache Across Multiple Servers
File caching allows you to store files your users might need to access during the time they're on your website or using your Web application. If you dedicate one server for caching, you could be placing an unnecessarily high amount of strain on the server. By distributing the caches, you distribute the load across your servers more evenly, thus giving you more collective computing power you can use for other things.
Instructions
-
-
1
Locate the database cache connection initialization in your code, for example:
define('DBHOSTSERVER', 'dbmaster');
define('DBUSER', 'username');
define('DBPASS', 'password');
$DB_SLAVES = array('dbslaveserver1','dbslaveserver2','dbslaveserver3');
-
2
Locate the current database that is being used for caching by executing the following code:
$db->conn_write = mysql_pconnect(DBHOSTSERVER, DBUSER, DBPASS);
mysql_select_db(DBNAME, $db->conn_write);
-
-
3
Pick the slave databases to distribute the caching by using the following code:
$idx = time () $ count($dbslaveserver1, dbslaveserver2, dbslaveserver3);
$slave = $dbslaveserver1, dbslaveserver2, dbslaveserver3($idx);
$db->conn_read = mysql_pconnect($slave, DBUSER, DBPASS);
mysql_select_db($dbslaveserver1, dbslaveserver2, dbslaveserver3, $db->conn_read);
-
1
References
- Photo Credit Comstock/Comstock/Getty Images