
Memcache::getExtendedStats 함수는 현재 연결된 Memcache 서버에만 적용되기 때문에, 여러 개의 Memcache 서버에 확장된 통계를 가져오려면 다음과 같은 방법을 사용할 수 있습니다.
1. 서버 연결을 분리하여 통계를 가져오기: 여러 개의 Memcache 서버를 분리하여 각각의 서버에 대해 Memcache::getExtendedStats 함수를 호출하여 확장된 통계를 가져올 수 있습니다.
#hostingforum.kr
php
$memcache = new Memcache;
$memcache->addServer('서버1 주소', 11211);
$memcache->addServer('서버2 주소', 11211);
$stats1 = $memcache->getExtendedStats();
$stats2 = $memcache->getExtendedStats();
print_r($stats1);
print_r($stats2);
2. Memcache 확장된 통계를 가져오는 함수를 만들기: Memcache 확장된 통계를 가져오는 함수를 만들어서 여러 개의 Memcache 서버에 대해 호출할 수 있습니다.
#hostingforum.kr
php
function getMemcacheExtendedStats($memcache, $serverAddress, $port) {
$memcache->addServer($serverAddress, $port);
return $memcache->getExtendedStats();
}
$memcache = new Memcache;
$memcache->addServer('서버1 주소', 11211);
$memcache->addServer('서버2 주소', 11211);
$stats1 = getMemcacheExtendedStats($memcache, '서버1 주소', 11211);
$stats2 = getMemcacheExtendedStats($memcache, '서버2 주소', 11211);
print_r($stats1);
print_r($stats2);
3. Memcache 확장된 통계를 가져오는 함수를 만들고 여러 개의 서버에 대해 호출하기: Memcache 확장된 통계를 가져오는 함수를 만들고 여러 개의 서버에 대해 호출할 수 있습니다.
#hostingforum.kr
php
function getMemcacheExtendedStats($memcache, $serverAddresses, $port) {
foreach ($serverAddresses as $serverAddress) {
$memcache->addServer($serverAddress, $port);
$stats = $memcache->getExtendedStats();
// 통계를 처리할 수 있도록 함수를 호출
processStats($stats);
}
}
function processStats($stats) {
// 통계를 처리하는 코드
}
$memcache = new Memcache;
$serverAddresses = array('서버1 주소', '서버2 주소');
$port = 11211;
getMemcacheExtendedStats($memcache, $serverAddresses, $port);
위의 방법 중 하나를 사용하여 Memcache 확장된 통계를 가져올 수 있습니다.
2025-08-07 06:47