public static function getSlaveConnection()
 {
     if (!is_null(self::$detectedSlave)) {
         return self::$detectedSlave;
     }
     $prefix = 'slave_';
     $list = array();
     $manager = sfContext::getInstance()->getDatabaseManager();
     foreach ($manager->getNames() as $name) {
         if (substr($name, 0, strlen($prefix)) === $prefix || 'doctrine' === $name || 'master' === $name) {
             $db = $manager->getDatabase($name);
             $list = array_pad($list, count($list) + (int) $db->getParameter('priority', 1), $name);
         }
     }
     shuffle($list);
     $key = array_shift($list);
     try {
         $connection = $manager->getDatabase($key)->getDoctrineConnection();
         self::$detectedSlave = $connection;
     } catch (Doctrine_Connection_Exception $e) {
         self::$detectedSlave = self::getMasterConnection();
     }
     return self::$detectedSlave;
 }