<?php define("ADMIN_MODULE_NAME", "cluster"); require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/cluster/include.php"; IncludeModuleLangFile(__FILE__); if (!$USER->IsAdmin()) { $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED")); } $arServer = CClusterMemcache::GetByID($_REQUEST["ID"]); $group_id = intval($_REQUEST["group_id"]); if (is_array($arServer) && $arServer["GROUP_ID"] != $group_id) { $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED")); } $aTabs = array(array("DIV" => "edit1", "TAB" => GetMessage("CLU_MEMCACHE_EDIT_TAB"), "ICON" => "main_user_edit", "TITLE" => GetMessage("CLU_MEMCACHE_EDIT_TAB_TITLE"))); $tabControl = new CAdminTabControl("tabControl", $aTabs); $strError = ""; $bVarsFromForm = false; if (!extension_loaded('memcache')) { require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php"; ShowError(GetMessage("CLU_MEMCACHE_NO_EXTENTION")); require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php"; } if ($REQUEST_METHOD == "POST" && check_bitrix_sessid()) { if ($save != "" || $apply != "") { $ob = new CClusterMemcache(); $arFields = array("GROUP_ID" => $group_id, "HOST" => $_POST["HOST"], "PORT" => $_POST["PORT"], "WEIGHT" => $_POST["WEIGHT"]); if (is_array($arServer)) { $res = $ob->Update($arServer["ID"], $arFields); } else { $res = $ob->Add($arFields);
} } $arHeaders = array(array("id" => "ID", "content" => GetMessage("CLU_MEMCACHE_LIST_ID"), "align" => "right", "default" => true), array("id" => "FLAG", "content" => GetMessage("CLU_MEMCACHE_LIST_FLAG"), "align" => "center", "default" => true), array("id" => "STATUS", "content" => GetMessage("CLU_MEMCACHE_LIST_STATUS"), "align" => "center", "default" => true), array("id" => "WEIGHT", "content" => GetMessage("CLU_MEMCACHE_LIST_WEIGHT"), "align" => "right", "default" => true), array("id" => "HOST", "content" => GetMessage("CLU_MEMCACHE_LIST_HOST"), "align" => "left", "default" => true)); $lAdmin->AddHeaders($arHeaders); if (!isset($_SESSION["MEMCACHE_LIST"])) { $_SESSION["MEMCACHE_LIST"] = array(); } $cData = new CClusterMemcache(); $rsData = $cData->GetList(); $uptime = false; $rsData = new CAdminResult($rsData, $sTableID); while ($arRes = $rsData->Fetch()) { if (!$arRes["GROUP_ID"]) { $arRes = CClusterMemcache::GetByID($arRes["ID"]); $cData->Update($arRes["ID"], $arRes); $arRes = CClusterMemcache::GetByID($arRes["ID"]); } if ($arRes["GROUP_ID"] != $group_id) { continue; } $row =& $lAdmin->AddRow($arRes["ID"], $arRes); $row->AddViewField("ID", '<a href="cluster_memcache_edit.php?lang=' . LANGUAGE_ID . '&group_id=' . $group_id . '&ID=' . $arRes["ID"] . '">' . $arRes["ID"] . '</a>'); $html = ''; if (true) { $html .= '<table width="100%">'; $arSlaveStatus = CClusterMemcache::GetStatus($arRes["ID"]); foreach ($arSlaveStatus as $key => $value) { if ($key == 'uptime') { $uptime = $value; } elseif ($key == 'get_misses') { $get_misses = $value;
function GetStatus($id) { $arStats = array(); $arServer = CClusterMemcache::GetByID($id); if (is_array($arServer)) { $ob = new Memcache(); if (@$ob->connect($arServer["HOST"], $arServer["PORT"])) { $arStats = array('uptime' => null, 'version' => null, 'cmd_get' => null, 'cmd_set' => null, 'get_misses' => null, 'get_hits' => null, 'limit_maxbytes' => null, 'bytes' => null, 'curr_items' => null, 'listen_disabled_num' => null); $ar = $ob->getStats(); foreach ($arStats as $key => $value) { $arStats[$key] = $ar[$key]; } } } return $arStats; }