개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.08.07 06:46

Memcache::getExtendedStats 사용법에 대한 질문

목록
  • 루트권한 17시간 전 2025.08.07 06:46 새글
  • 5
    1
저는 PHP에서 Memcache::getExtendedStats 함수를 사용하여 메모리 캐시의 확장된 통계를 가져오려고 합니다. 하지만 이 함수를 사용할 때 발생하는 에러 중 하나인 'Memcache::getExtendedStats() 메소드는 현재 연결된 Memcache 서버에만 적용됩니다' 에러를 어떻게 해결해야 하는지 궁금합니다.

이 에러는 현재 연결된 Memcache 서버가 여러 개일 때 발생하는 것으로 보입니다. 이 경우에 Memcache::getExtendedStats 함수를 사용하여 확장된 통계를 가져올 수 있는 방법은 무엇이 있을까요?

    댓글목록

    profile_image
    나우호스팅  17시간 전



    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

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 42,268건 / 12 페이지

검색

게시물 검색