Exemplo n.º 1
0
    function SaveConfig($arServerList)
    {
        self::$arList = false;
        $isOnline = false;
        $content = '<' . '?
define("BX_MEMCACHE_CLUSTER", "' . EscapePHPString(CMain::GetServerUniqID()) . '");
$arList = array(
';
        $defGroup = 1;
        $arGroups = array();
        $rsGroups = CClusterGroup::GetList(array("ID" => "DESC"));
        while ($arGroup = $rsGroups->Fetch()) {
            $defGroup = $arGroups[$arGroup["ID"]] = intval($arGroup["ID"]);
        }
        foreach ($arServerList as $i => $arServer) {
            $isOnline |= $arServer["STATUS"] == "ONLINE";
            $GROUP_ID = intval($arServer["GROUP_ID"]);
            if (!array_key_exists($arServer["GROUP_ID"], $arGroups)) {
                $GROUP_ID = $defGroup;
            }
            $content .= "\t" . intval($i) . " => array(\n";
            $content .= "\t\t'ID' => \"" . EscapePHPString($arServer["ID"]) . "\",\n";
            $content .= "\t\t'GROUP_ID' => " . $GROUP_ID . ",\n";
            $content .= "\t\t'HOST' => \"" . EscapePHPString($arServer["HOST"]) . "\",\n";
            $content .= "\t\t'PORT' => " . intval($arServer["PORT"]) . ",\n";
            $content .= "\t\t'WEIGHT' => " . intval($arServer["WEIGHT"]) . ",\n";
            if ($arServer["STATUS"] == "ONLINE") {
                $content .= "\t\t'STATUS' => \"ONLINE\",\n";
            } elseif ($arServer["STATUS"] == "OFFLINE") {
                $content .= "\t\t'STATUS' => \"OFFLINE\",\n";
            } else {
                $content .= "\t\t'STATUS' => \"READY\",\n";
            }
            $content .= "\t),\n";
        }
        $content .= ');
?' . '>';
        file_put_contents($_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/cluster/memcache.php", $content);
        bx_accelerator_reset();
        self::$systemConfigurationUpdate = null;
        $cache = \Bitrix\Main\Config\Configuration::getValue('cache');
        if ($isOnline) {
            if (!is_array($cache) || !isset($cache['type']) || !is_array($cache['type']) || !isset($cache['type']['class_name']) || !$cache['type']['class_name'] === 'CPHPCacheMemcacheCluster') {
                \Bitrix\Main\Config\Configuration::setValue('cache', array('type' => array('class_name' => 'CPHPCacheMemcacheCluster', 'extension' => 'memcache', 'required_file' => 'modules/cluster/classes/general/memcache_cache.php')));
                self::$systemConfigurationUpdate = true;
            }
        } else {
            if (is_array($cache) && isset($cache['type']) && is_array($cache['type']) && isset($cache['type']['class_name']) && $cache['type']['class_name'] === 'CPHPCacheMemcacheCluster') {
                \Bitrix\Main\Config\Configuration::setValue('cache', null);
                self::$systemConfigurationUpdate = false;
            }
        }
    }
Exemplo n.º 2
0
	public static function SaveConfig($arServerList)
	{
		self::$arList = false;
		$content = '<'.'?
// define("BX_MEMCACHE_CLUSTER", "'.EscapePHPString(CMain::GetServerUniqID()).'");
$arList = array(
';
		$defGroup = 1;
		$arGroups = array();
		$rsGroups = CClusterGroup::GetList(array("ID" => "DESC"));
		while($arGroup = $rsGroups->Fetch())
			$defGroup = $arGroups[$arGroup["ID"]] = intval($arGroup["ID"]);

		foreach($arServerList as $i => $arServer)
		{
			$GROUP_ID = intval($arServer["GROUP_ID"]);
			if(!array_key_exists($arServer["GROUP_ID"], $arGroups))
				$GROUP_ID = $defGroup;

			$content .= "\t".intval($i)." => array(\n";
			$content .= "\t\t'ID' => \"".EscapePHPString($arServer["ID"])."\",\n";
			$content .= "\t\t'GROUP_ID' => ".$GROUP_ID.",\n";
			$content .= "\t\t'HOST' => \"".EscapePHPString($arServer["HOST"])."\",\n";
			$content .= "\t\t'PORT' => ".intval($arServer["PORT"]).",\n";
			$content .= "\t\t'WEIGHT' => ".intval($arServer["WEIGHT"]).",\n";
			if($arServer["STATUS"] == "ONLINE")
				$content .= "\t\t'STATUS' => \"ONLINE\",\n";
			elseif($arServer["STATUS"] == "OFFLINE")
				$content .= "\t\t'STATUS' => \"OFFLINE\",\n";
			else
				$content .= "\t\t'STATUS' => \"READY\",\n";
			$content .= "\t),\n";
		}

		$content .= ');
?'.'>';
		file_put_contents(
			$_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/cluster/memcache.php"
			,$content
		);
	}