How to Cache Across Multiple Servers

104 7
    • 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);

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.