本文整理汇总了PHP中LoadBalancer::getServerInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP LoadBalancer::getServerInfo方法的具体用法?PHP LoadBalancer::getServerInfo怎么用?PHP LoadBalancer::getServerInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LoadBalancer
的用法示例。
在下文中一共展示了LoadBalancer::getServerInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}