• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP LoadBalancer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中LoadBalancer的典型用法代码示例。如果您正苦于以下问题:PHP LoadBalancer类的具体用法?PHP LoadBalancer怎么用?PHP LoadBalancer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了LoadBalancer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: getMainLB

 /**
  * @param bool|string $wiki
  * @return LoadBalancer
  */
 public function getMainLB($wiki = false)
 {
     if (!isset($this->mainLB)) {
         $this->mainLB = $this->newMainLB($wiki);
         $this->mainLB->parentInfo(array('id' => 'main'));
         $this->chronProt->initLB($this->mainLB);
     }
     return $this->mainLB;
 }
开发者ID:Gomyul,项目名称:mediawiki,代码行数:13,代码来源:LBFactorySimple.php


示例2:

 /**
  * Fetch data from given URL
  * @param string $url An url
  */
 function &getLoadBalancer($cluster)
 {
     global $wgExternalServers;
     if (!array_key_exists($cluster, $this->loadBalancers)) {
         $this->loadBalancers[$cluster] = LoadBalancer::newFromParams($wgExternalServers[$cluster]);
     }
     return $this->loadBalancers[$cluster];
 }
开发者ID:BackupTheBerlios,项目名称:openzaurus-svn,代码行数:12,代码来源:ExternalStoreDB.php


示例3:

 /** @todo Document.*/
 function &getLoadBalancer($cluster)
 {
     global $wgExternalServers, $wgExternalLoadBalancers;
     if (!array_key_exists($cluster, $wgExternalLoadBalancers)) {
         $wgExternalLoadBalancers[$cluster] = LoadBalancer::newFromParams($wgExternalServers[$cluster]);
     }
     $wgExternalLoadBalancers[$cluster]->allowLagged(true);
     return $wgExternalLoadBalancers[$cluster];
 }
开发者ID:puring0815,项目名称:OpenKore,代码行数:10,代码来源:ExternalStoreDB.php


示例4: clear

 /**
  * Clears the list of sites stored in the database.
  *
  * @see SiteStore::clear()
  *
  * @return bool Success
  */
 public function clear()
 {
     $dbw = $this->dbLoadBalancer->getConnection(DB_MASTER);
     $dbw->startAtomic(__METHOD__);
     $ok = $dbw->delete('sites', '*', __METHOD__);
     $ok = $dbw->delete('site_identifiers', '*', __METHOD__) && $ok;
     $dbw->endAtomic(__METHOD__);
     $this->reset();
     return $ok;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:17,代码来源:DBSiteStore.php


示例5: shutdownLB

 /**
  * Notify the ChronologyProtector that the LoadBalancer is about to shut
  * down. Saves replication positions.
  *
  * @param LoadBalancer $lb
  * @return void
  */
 public function shutdownLB(LoadBalancer $lb)
 {
     if (session_id() == '' || $lb->getServerCount() <= 1) {
         return;
         // don't start a session; don't bother with non-replicated setups
     }
     $masterName = $lb->getServerName(0);
     if (isset($this->shutdownPositions[$masterName])) {
         return;
         // already done
     }
     // Only save the position if writes have been done on the connection
     $db = $lb->getAnyOpenConnection(0);
     $info = $lb->parentInfo();
     if (!$db || !$db->doneWrites()) {
         wfDebug(__METHOD__ . ": LB {$info['id']}, no writes done\n");
         return;
     }
     $pos = $db->getMasterPos();
     wfDebug(__METHOD__ . ": LB {$info['id']} has master pos {$pos}\n");
     $this->shutdownPositions[$masterName] = $pos;
 }
开发者ID:jpena88,项目名称:mediawiki-dokku-deploy,代码行数:29,代码来源:ChronologyProtector.php


示例6: getDB

 /**
  * @return DatabaseBase
  */
 protected function getDB()
 {
     if (!isset($this->db)) {
         # If server connection info was given, use that
         if ($this->serverInfo) {
             $this->lb = new LoadBalancer(array('servers' => array($this->serverInfo)));
             $this->db = $this->lb->getConnection(DB_MASTER);
             $this->db->clearFlag(DBO_TRX);
         } else {
             # We must keep a separate connection to MySQL in order to avoid deadlocks
             # However, SQLite has an opposite behaviour.
             # @todo Investigate behaviour for other databases
             if (wfGetDB(DB_MASTER)->getType() == 'sqlite') {
                 $this->db = wfGetDB(DB_MASTER);
             } else {
                 $this->lb = wfGetLBFactory()->newMainLB();
                 $this->db = $this->lb->getConnection(DB_MASTER);
                 $this->db->clearFlag(DBO_TRX);
             }
         }
     }
     return $this->db;
 }
开发者ID:eFFemeer,项目名称:seizamcore,代码行数:26,代码来源:SqlBagOStuff.php


示例7: fetchFromURL

 /**
  * Fetch data from given URL
  * @param string $url An url
  */
 function fetchFromURL($url)
 {
     global $wgExternalServers;
     #
     # URLs have the form DB://cluster/id, e.g.
     # DB://cluster1/3298247
     #
     $path = explode('/', $url);
     $cluster = $path[2];
     $id = $path[3];
     $lb = LoadBalancer::NewFromParams($wgExternalServers[$cluster]);
     $db = $lb->getConnection(DB_SLAVE);
     $ret = $db->selectField('blobs', 'blob_text', array('blob_id' => $id));
     return $ret;
 }
开发者ID:BackupTheBerlios,项目名称:blahtex,代码行数:19,代码来源:ExternalStoreDB.php


示例8: getDB

 /**
  * @return DatabaseBase
  */
 protected function getDB()
 {
     global $wgDebugDBTransactions;
     # Don't keep timing out trying to connect for each call if the DB is down
     if ($this->connFailureError && time() - $this->connFailureTime < 60) {
         throw $this->connFailureError;
     }
     if (!isset($this->db)) {
         # If server connection info was given, use that
         if ($this->serverInfo) {
             if ($wgDebugDBTransactions) {
                 wfDebug(sprintf("Using provided serverInfo for SqlBagOStuff\n"));
             }
             $this->lb = new LoadBalancer(array('servers' => array($this->serverInfo)));
             $this->db = $this->lb->getConnection(DB_MASTER);
             $this->db->clearFlag(DBO_TRX);
         } else {
             /*
              * We must keep a separate connection to MySQL in order to avoid deadlocks
              * However, SQLite has an opposite behaviour. And PostgreSQL needs to know
              * if we are in transaction or no
              */
             if (wfGetDB(DB_MASTER)->getType() == 'mysql') {
                 $this->lb = wfGetLBFactory()->newMainLB();
                 $this->db = $this->lb->getConnection(DB_MASTER);
                 $this->db->clearFlag(DBO_TRX);
                 // auto-commit mode
             } else {
                 $this->db = wfGetDB(DB_MASTER);
             }
         }
         if ($wgDebugDBTransactions) {
             wfDebug(sprintf("Connection %s will be used for SqlBagOStuff\n", $this->db));
         }
     }
     return $this->db;
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:40,代码来源:SqlBagOStuff.php


示例9: __construct

 /**
  * builds a new Node object
  *
  * @param LoadBalancer $lb the parent LB object
  * @param mixed $info either an ID or an array of values
  * @returns void
  */
 public function __construct(LoadBalancer $lb, $info = NULL)
 {
     $this->_lb = $lb;
     parent::__construct($lb->Service(), $info);
 }
开发者ID:aaronpburke,项目名称:cron-backup-script,代码行数:12,代码来源:lbresources.php


示例10: changeLBPrefix

 /**
  * @param LoadBalancer $lb
  * @param string $prefix
  * @return void
  */
 public static function changeLBPrefix($lb, $prefix)
 {
     $lb->forEachOpenConnection(array('CloneDatabase', 'changeDBPrefix'), array($prefix));
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:9,代码来源:CloneDatabase.php


示例11: shutdownLB

 /**
  * Notify the ChronologyProtector that the LoadBalancer is about to shut
  * down. Saves replication positions.
  *
  * @param LoadBalancer $lb
  */
 function shutdownLB($lb)
 {
     if (session_id() != '' && $lb->getServerCount() > 1) {
         $masterName = $lb->getServerName(0);
         if (!isset($this->shutdownPos[$masterName])) {
             $pos = $lb->getMasterPos();
             $info = $lb->parentInfo();
             wfDebug(__METHOD__ . ": LB " . $info['id'] . " has master pos {$pos}\n");
             $this->shutdownPos[$masterName] = $pos;
         }
     }
 }
开发者ID:amjadtbssm,项目名称:website,代码行数:18,代码来源:LBFactory.php


示例12: session_name

     session_name($wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session');
 }
 if (!$wgCommandLineMode && (isset($_COOKIE[session_name()]) || isset($_COOKIE[$wgCookiePrefix . 'Token']))) {
     wfIncrStats('request_with_session');
     User::SetupSession();
     $wgSessionStarted = true;
 } else {
     wfIncrStats('request_without_session');
     $wgSessionStarted = false;
 }
 wfProfileOut($fname . '-SetupSession');
 wfProfileIn($fname . '-database');
 if (!$wgDBservers) {
     $wgDBservers = array(array('host' => $wgDBserver, 'user' => $wgDBuser, 'password' => $wgDBpassword, 'dbname' => $wgDBname, 'type' => $wgDBtype, 'load' => 1, 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT));
 }
 $wgLoadBalancer = LoadBalancer::newFromParams($wgDBservers, false, $wgMasterWaitTimeout);
 $wgLoadBalancer->loadMasterPos();
 wfProfileOut($fname . '-database');
 wfProfileIn($fname . '-language1');
 require_once "{$IP}/languages/Language.php";
 function setupLangObj($langclass)
 {
     global $IP;
     if (!class_exists($langclass)) {
         # Default to English/UTF-8
         $baseclass = 'LanguageUtf8';
         require_once "{$IP}/languages/{$baseclass}.php";
         $lc = strtolower(substr($langclass, 8));
         $snip = "\n\t\t\tclass {$langclass} extends {$baseclass} {\n\t\t\t\tfunction getVariants() {\n\t\t\t\t\treturn array(\"{$lc}\");\n\t\t\t\t}\n\n\t\t\t}";
         eval($snip);
     }
开发者ID:k-hasan-19,项目名称:wiki,代码行数:31,代码来源:Setup.php


示例13: testHost

 /**
  * Execute checks for a single database server
  * @param string $databaseName Database name to use for connection
  * @param LoadBalancer $loadBalancer Load Balancer instance for the given cluster
  * @param int $index Server index to test
  * @return bool Is server healthy?
  * @throws MWException
  */
 private function testHost($databaseName, LoadBalancer $loadBalancer, $index)
 {
     $serverInfo = $loadBalancer->getServerInfo($index);
     $master = $index == 0;
     // connection check
     try {
         $db = wfGetDB($index, array(), $databaseName);
     } catch (DBError $e) {
         $this->addError("could not connect to server: " . $e->getMessage());
         return false;
     }
     // lag check
     if (!$master && isset($serverInfo['max lag'])) {
         try {
             $maxLag = $serverInfo['max lag'];
             $lag = $db->getLag();
             if ($lag > $maxLag) {
                 $this->addError("lag (%d) is greater than configured \"max lag\" (%d)", $lag, $maxLag);
                 $db->close();
                 return false;
             }
         } catch (DBError $e) {
             $this->addError("could not fetch lag time");
             $db->close();
             return false;
         }
     }
     // read_only check on master
     try {
         $res = $db->query("SHOW VARIABLES LIKE 'read_only';");
         $row = $res->fetchRow();
         $res->free();
         $readWrite = $row['Value'] != 'ON';
         if ($master && !$readWrite) {
             $this->addMessage("read_only is set on master host");
         } else {
             if (!$master && $readWrite) {
                 $this->addMessage("read_only is unset on slave host");
             }
         }
     } catch (DBError $e) {
         $this->addError("could not check read_only flag");
         $db->close();
         return false;
     }
     $db->close();
     return true;
 }
开发者ID:yusufchang,项目名称:app,代码行数:56,代码来源:HealthController.class.php


示例14: shutdownLB

 /**
  * Notify the ChronologyProtector that the LoadBalancer is about to shut
  * down. Saves replication positions.
  *
  * @param LoadBalancer $lb
  * @return void
  */
 public function shutdownLB(LoadBalancer $lb)
 {
     if (!$this->enabled || $lb->getServerCount() <= 1) {
         return;
         // non-replicated setup or disabled
     }
     $info = $lb->parentInfo();
     $masterName = $lb->getServerName($lb->getWriterIndex());
     // Only save the position if writes have been done on the connection
     $db = $lb->getAnyOpenConnection($lb->getWriterIndex());
     if (!$db || !$db->doneWrites()) {
         wfDebugLog('replication', __METHOD__ . ": LB {$info['id']}, no writes done\n");
         return;
         // nothing to do
     }
     $pos = $db->getMasterPos();
     wfDebugLog('replication', __METHOD__ . ": LB {$info['id']} has master pos {$pos}\n");
     $this->shutdownPositions[$masterName] = $pos;
 }
开发者ID:mb720,项目名称:mediawiki,代码行数:26,代码来源:ChronologyProtector.php


示例15: changeLBPrefix

 /**
  * @param LoadBalancer $lb
  * @param string $prefix
  * @return void
  */
 public static function changeLBPrefix($lb, $prefix)
 {
     $lb->forEachOpenConnection(['CloneDatabase', 'changeDBPrefix'], [$prefix]);
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:9,代码来源:CloneDatabase.php


示例16: newFromParams

 function newFromParams($servers, $failFunction = false, $waitTimeout = 10)
 {
     $lb = new LoadBalancer();
     $lb->initialise($servers, $failFunction, $waitTimeout);
     return $lb;
 }
开发者ID:BackupTheBerlios,项目名称:blahtex,代码行数:6,代码来源:LoadBalancer.php


示例17: getLagTimes

 public function getLagTimes($serverIndexes, $wiki)
 {
     if (count($serverIndexes) == 1 && reset($serverIndexes) == 0) {
         // Single server only, just return zero without caching
         return array(0 => 0);
     }
     $expiry = 5;
     $requestRate = 10;
     $cache = $this->cache;
     $masterName = $this->parent->getServerName(0);
     $memcKey = wfMemcKey('lag_times', $masterName);
     $times = $cache->get($memcKey);
     if (is_array($times)) {
         # Randomly recache with probability rising over $expiry
         $elapsed = time() - $times['timestamp'];
         $chance = max(0, ($expiry - $elapsed) * $requestRate);
         if (mt_rand(0, $chance) != 0) {
             unset($times['timestamp']);
             // hide from caller
             return $times;
         }
         wfIncrStats('lag_cache.miss.expired');
     } else {
         wfIncrStats('lag_cache.miss.absent');
     }
     # Cache key missing or expired
     if ($cache->lock($memcKey, 0, 10)) {
         # Let this process alone update the cache value
         $unlocker = new ScopedCallback(function () use($cache, $memcKey) {
             $cache->unlock($memcKey);
         });
     } elseif (is_array($times)) {
         # Could not acquire lock but an old cache exists, so use it
         unset($times['timestamp']);
         // hide from caller
         return $times;
     }
     $times = array();
     foreach ($serverIndexes as $i) {
         if ($i == 0) {
             # Master
             $times[$i] = 0;
         } elseif (false !== ($conn = $this->parent->getAnyOpenConnection($i))) {
             $times[$i] = $conn->getLag();
         } elseif (false !== ($conn = $this->parent->openConnection($i, $wiki))) {
             $times[$i] = $conn->getLag();
             // Close the connection to avoid sleeper connections piling up.
             // Note that the caller will pick one of these DBs and reconnect,
             // which is slightly inefficient, but this only matters for the lag
             // time cache miss cache, which is far less common that cache hits.
             $this->parent->closeConnection($conn);
         }
     }
     # Add a timestamp key so we know when it was cached
     $times['timestamp'] = time();
     $cache->set($memcKey, $times, $expiry + 10);
     unset($times['timestamp']);
     // hide from caller
     return $times;
 }
开发者ID:GoProjectOwner,项目名称:mediawiki,代码行数:60,代码来源:LoadMonitor.php


示例18: getLagTimes

 public function getLagTimes($serverIndexes, $wiki)
 {
     if (count($serverIndexes) == 1 && reset($serverIndexes) == 0) {
         // Single server only, just return zero without caching
         return array(0 => 0);
     }
     $section = new ProfileSection(__METHOD__);
     $expiry = 5;
     $requestRate = 10;
     global $wgMemc;
     if (empty($wgMemc)) {
         $wgMemc = wfGetMainCache();
     }
     $masterName = $this->parent->getServerName(0);
     $memcKey = wfMemcKey('lag_times', $masterName);
     $times = $wgMemc->get($memcKey);
     if (is_array($times)) {
         # Randomly recache with probability rising over $expiry
         $elapsed = time() - $times['timestamp'];
         $chance = max(0, ($expiry - $elapsed) * $requestRate);
         if (mt_rand(0, $chance) != 0) {
             unset($times['timestamp']);
             // hide from caller
             return $times;
         }
         wfIncrStats('lag_cache_miss_expired');
     } else {
         wfIncrStats('lag_cache_miss_absent');
     }
     # Cache key missing or expired
     if ($wgMemc->add("{$memcKey}:lock", 1, 10)) {
         # Let this process alone update the cache value
         $unlocker = new ScopedCallback(function () use($wgMemc, $memcKey) {
             $wgMemc->delete($memcKey);
         });
     } elseif (is_array($times)) {
         # Could not acquire lock but an old cache exists, so use it
         unset($times['timestamp']);
         // hide from caller
         return $times;
     }
     $times = array();
     foreach ($serverIndexes as $i) {
         if ($i == 0) {
             # Master
             $times[$i] = 0;
         } elseif (false !== ($conn = $this->parent->getAnyOpenConnection($i))) {
             $times[$i] = $conn->getLag();
         } elseif (false !== ($conn = $this->parent->openConnection($i, $wiki))) {
             $times[$i] = $conn->getLag();
         }
     }
     # Add a timestamp key so we know when it was cached
     $times['timestamp'] = time();
     $wgMemc->set($memcKey, $times, $expiry + 10);
     unset($times['timestamp']);
     // hide from caller
     return $times;
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:59,代码来源:LoadMonitor.php


示例19: __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


示例20: getLagTimes

 /**
  * @param $serverIndexes
  * @param $wiki
  * @return array
  */
 function getLagTimes($serverIndexes, $wiki)
 {
     if (count($serverIndexes) == 1 && reset($serverIndexes) == 0) {
         // Single server only, just return zero without caching
         return array(0 => 0);
     }
     wfProfileIn(__METHOD__);
     $expiry = 5;
     $requestRate = 10;
     global $wgMemc;
     if (empty($wgMemc)) {
         $wgMemc = wfGetMainCache();
     }
     $masterName = $this->parent->getServerName(0);
     $memcKey = wfMemcKey('lag_times', $masterName);
     $times = $wgMemc->get($memcKey);
     if ($times) {
         # Randomly recache with probability rising over $expiry
         $elapsed = time() - $times['timestamp'];
         $chance = max(0, ($expiry - $elapsed) * $requestRate);
         if (mt_rand(0, $chance) != 0) {
             unset($times['timestamp']);
             wfProfileOut(__METHOD__);
             return $times;
         }
         wfIncrStats('lag_cache_miss_expired');
     } else {
         wfIncrStats('lag_cache_miss_absent');
     }
     # Cache key missing or expired
     $times = array();
     foreach ($serverIndexes as $i) {
         if ($i == 0) {
             # Master
             $times[$i] = 0;
         } elseif (false !== ($conn = $this->parent->getAnyOpenConnection($i))) {
             $times[$i] = $conn->getLag();
         } elseif (false !== ($conn = $this->parent->openConnection($i, $wiki))) {
             $times[$i] = $conn->getLag();
         }
     }
     # Add a timestamp key so we know when it was cached
     $times['timestamp'] = time();
     $wgMemc->set($memcKey, $times, $expiry);
     # But don't give the timestamp to the caller
     unset($times['timestamp']);
     $lagTimes = $times;
     wfProfileOut(__METHOD__);
     return $lagTimes;
 }
开发者ID:eFFemeer,项目名称:seizamcore,代码行数:55,代码来源:LoadMonitor.php



注:本文中的LoadBalancer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Loader类代码示例发布时间:2022-05-23
下一篇:
PHP Load类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap