[horde] adding backup servers to mysql db driver

Joseph W. Breu breu at cfu.net
Thu Jan 4 20:07:10 PST 2007


Hi All,

In our environment, we have 2 r/w database servers using redundancy to  
store session and user pref data.  We also have 2 r/o servers for our  
mail exchangers to query.

I started looking at the process for adding backup database servers to  
Horde.  The SessionHandler was pretty easy (changes to  
Horde/SessionHandler/mysql.php attached).  The basic idea is to try  
the second server if the first fails and only provide the db connect  
error if the second try fails.

However, I was looking at modifying the rest of the Horde mysql db  
backend.  Has this already been worked on?


Thanks,

---------------------------------------------------------
Joseph W. Breu, CCNA              phone : +1.319.268.5228
Senior Network Administrator        fax : +1.319.266.8158
Cedar Falls Utilities              cell : +1.319.493.1686
support: +1.319.268.5221         url : http://www.cfu.net
-------------- next part --------------
--- /usr/share/pear/Horde/SessionHandler/mysql.php.orig	2007-01-04 16:33:02.000000000 -0600
+++ /usr/share/pear/Horde/SessionHandler/mysql.php	2007-01-04 21:37:00.000000000 -0600
@@ -323,11 +323,17 @@
         }
 
         if (!$this->_db = @$connect($this->_params['hostspec'] . (!empty($this->_params['port']) ? ':' . $this->_params['port'] : ''),
                                     $this->_params['username'],
                                     $this->_params['password'])) {
-            return PEAR::raiseError('Could not connect to database for SQL SessionHandler.');
+                /* original db connect failed - try the backup server */
+        	if (!$this->_db = @$connect($this->_params['hostspecbackup'] . (!empty($this->_params['port']) ? ':' . $this->_params['port'] : ''),
+                                    	$this->_params['username'],
+                                    	$this->_params['password'])) {
+
+            		return PEAR::raiseError('Could not connect to database for SQL SessionHandler.');
+		}
         }
 
         if (!@mysql_select_db($this->_params['database'], $this->_db)) {
             return PEAR::raiseError(sprintf('Could not connect to database %s for SQL SessionHandler.', $this->_params['database']));
         }


More information about the horde mailing list