當前位置: 首頁>>代碼示例>>PHP>>正文


PHP IDatabase::getServer方法代碼示例

本文整理匯總了PHP中IDatabase::getServer方法的典型用法代碼示例。如果您正苦於以下問題:PHP IDatabase::getServer方法的具體用法?PHP IDatabase::getServer怎麽用?PHP IDatabase::getServer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在IDatabase的用法示例。


在下文中一共展示了IDatabase::getServer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * @param array $params An associative array with one member:
  *   - connection: An IDatabase connection object
  */
 public function __construct(array $params)
 {
     if (!isset($params['connection'])) {
         throw new InvalidArgumentException("Missing 'connection' argument.");
     }
     $this->db = $params['connection'];
     parent::__construct(['servers' => [['type' => $this->db->getType(), 'host' => $this->db->getServer(), 'dbname' => $this->db->getDBname(), 'load' => 1]], 'trxProfiler' => isset($params['trxProfiler']) ? $params['trxProfiler'] : null, 'srvCache' => isset($params['srvCache']) ? $params['srvCache'] : null, 'wanCache' => isset($params['wanCache']) ? $params['wanCache'] : null]);
     if (isset($params['readOnlyReason'])) {
         $this->db->setLBInfo('readOnlyReason', $params['readOnlyReason']);
     }
 }
開發者ID:paladox,項目名稱:mediawiki,代碼行數:15,代碼來源:LoadBalancerSingle.php

示例2: safeWaitForMasterPos

 /**
  * Wait for a slave DB to reach a specified master position
  *
  * This will connect to the master to get an accurate position if $pos is not given
  *
  * @param IDatabase $conn Slave DB
  * @param DBMasterPos|bool $pos Master position; default: current position
  * @param integer $timeout Timeout in seconds
  * @return bool Success
  * @since 1.27
  */
 public function safeWaitForMasterPos(IDatabase $conn, $pos = false, $timeout = 10)
 {
     if ($this->getServerCount() == 1 || !$conn->getLBInfo('slave')) {
         return true;
         // server is not a slave DB
     }
     $pos = $pos ?: $this->getConnection(DB_MASTER)->getMasterPos();
     if (!$pos) {
         return false;
         // something is misconfigured
     }
     $result = $conn->masterPosWait($pos, $timeout);
     if ($result == -1 || is_null($result)) {
         $msg = __METHOD__ . ": Timed out waiting on {$conn->getServer()} pos {$pos}";
         wfDebugLog('replication', "{$msg}\n");
         wfDebugLog('DBPerformance', "{$msg}:\n" . wfBacktrace(true));
         $ok = false;
     } else {
         wfDebugLog('replication', __METHOD__ . ": Done\n");
         $ok = true;
     }
     return $ok;
 }
開發者ID:admonkey,項目名稱:mediawiki,代碼行數:34,代碼來源:LoadBalancer.php

示例3: safeWaitForMasterPos

 public function safeWaitForMasterPos(IDatabase $conn, $pos = false, $timeout = 10)
 {
     if ($this->getServerCount() <= 1 || !$conn->getLBInfo('replica')) {
         return true;
         // server is not a replica DB
     }
     if (!$pos) {
         // Get the current master position, opening a connection if needed
         $masterConn = $this->getAnyOpenConnection($this->getWriterIndex());
         if ($masterConn) {
             $pos = $masterConn->getMasterPos();
         } else {
             $masterConn = $this->openConnection($this->getWriterIndex(), self::DOMAIN_ANY);
             $pos = $masterConn->getMasterPos();
             $this->closeConnection($masterConn);
         }
     }
     if ($pos instanceof DBMasterPos) {
         $result = $conn->masterPosWait($pos, $timeout);
         if ($result == -1 || is_null($result)) {
             $msg = __METHOD__ . ": Timed out waiting on {$conn->getServer()} pos {$pos}";
             $this->replLogger->warning("{$msg}");
             $ok = false;
         } else {
             $this->replLogger->info(__METHOD__ . ": Done");
             $ok = true;
         }
     } else {
         $ok = false;
         // something is misconfigured
         $this->replLogger->error("Could not get master pos for {$conn->getServer()}.");
     }
     return $ok;
 }
開發者ID:paladox,項目名稱:mediawiki,代碼行數:34,代碼來源:LoadBalancer.php


注:本文中的IDatabase::getServer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。