라이브러리

[PHP] MongoDBDriverMonitoringServerOpeningEvent::getTopologyId - 이 서버와 연관된 토폴로지 ID를 반환합니다.




MongoDB Driver Monitoring Server Opening Event


MongoDB Driver Monitoring Server Opening Event는 MongoDB 드라이버의 모니터링 기능을 사용하여 MongoDB 서버가 열릴 때 발생하는 이벤트입니다. 이 이벤트는 MongoDB 서버의 토폴로지 ID를 포함하여 서버의 정보를 제공합니다.

getTopologyId 메서드


getTopologyId 메서드는 MongoDB 서버의 토폴로지 ID를 반환하는 메서드입니다. 이 메서드는 MongoDB 서버가 열릴 때 발생하는 이벤트에서 사용할 수 있습니다.

예제


아래 예제는 MongoDB 드라이버의 모니터링 기능을 사용하여 MongoDB 서버가 열릴 때 발생하는 이벤트를 처리하는 방법을 보여줍니다.

#hostingforum.kr
php

use MongoDBDriverMonitoringServerOpeningEvent;

use MongoDBDriverMonitoringServerOpeningCallback;



// MongoDB 서버에 연결

$m = new MongoDBDriverManager('mongodb://localhost:27017');



// 서버 열기 이벤트를 처리하는 콜백 함수

$callback = new class implements ServerOpeningCallback {

    public function __invoke(ServerOpeningEvent $event) {

        // 서버의 토폴로지 ID를 가져옵니다.

        $topologyId = $event->getTopologyId();



        // 서버의 토폴로지 ID를 출력합니다.

        echo "서버의 토폴로지 ID: $topologyId
";

    }

};



// 서버 열기 이벤트를 등록합니다.

$m->addServerOpeningCallback($callback);



사용 방법


1. MongoDB 드라이버의 모니터링 기능을 사용하여 MongoDB 서버가 열릴 때 발생하는 이벤트를 처리하려면 `ServerOpeningCallback` 인터페이스를 구현하는 콜백 함수를 생성해야 합니다.
2. 콜백 함수에서 `getTopologyId` 메서드를 사용하여 MongoDB 서버의 토폴로지 ID를 가져올 수 있습니다.
3. 콜백 함수를 MongoDB 드라이버의 `addServerOpeningCallback` 메서드를 사용하여 서버 열기 이벤트에 등록합니다.

참고 자료


* MongoDB Driver Monitoring:
* MongoDB Driver Monitoring Server Opening Event:
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 392 페이지

검색

게시물 검색