라이브러리

[PHP] MongoDBDriverMonitoringServerChangedEvent::getPreviousDescription - 서버에 대한 이전 설명을 반환합니다.




MongoDB Driver Monitoring Server Changed Event

MongoDB Driver Monitoring은 MongoDB Driver가 제공하는 모니터링 기능으로, MongoDB 서버와의 연결 상태를 모니터링할 수 있습니다. 이 기능을 사용하면 MongoDB 서버의 연결 상태를 실시간으로 확인할 수 있습니다.

MongoDBDriverMonitoringServerChangedEvent

`MongoDBDriverMonitoringServerChangedEvent`는 MongoDB Driver Monitoring에서 발생하는 이벤트 중 하나입니다. 이 이벤트는 MongoDB 서버의 연결 상태가 변경되었을 때 발생합니다. 예를 들어, MongoDB 서버와의 연결이 끊겼다가 다시 연결된 경우 이 이벤트가 발생합니다.

이벤트의 `getPreviousDescription()` 메서드는 이전에 연결된 MongoDB 서버의 설명을 반환합니다. 이 설명은 MongoDB 서버의 호스트 이름, 포트 번호, 데이터베이스 이름 등과 같은 정보를 포함합니다.

예제

다음 예제는 `MongoDBDriverMonitoringServerChangedEvent`를 사용하여 이전에 연결된 MongoDB 서버의 설명을 가져오는 방법을 보여줍니다.
#hostingforum.kr
php

use MongoDBDriverMonitoringServerChangedEvent;

use MongoDBDriverMonitoringServerChangedEventInterface;



// MongoDB 서버와의 연결을 설정합니다.

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



// MongoDB Driver Monitoring을 사용하여 이벤트를 등록합니다.

$monitor = new MongoDBDriverMonitoringServerMonitor($m);

$monitor->addSubscriber(new MongoDBDriverMonitoringEventSubscriber());



// MongoDB 서버와의 연결이 변경되었을 때 이벤트를 수신합니다.

$monitor->addSubscriber(new class implements ServerChangedEventInterface {

    public function onServerChanged(ServerChangedEvent $event) {

        // 이전에 연결된 MongoDB 서버의 설명을 가져옵니다.

        $previousDescription = $event->getPreviousDescription();

        echo "이전 연결된 MongoDB 서버의 설명: " . $previousDescription->getHost() . ":" . $previousDescription->getPort() . "
";



        // 현재 연결된 MongoDB 서버의 설명을 가져옵니다.

        $currentDescription = $event->getDescription();

        echo "현재 연결된 MongoDB 서버의 설명: " . $currentDescription->getHost() . ":" . $currentDescription->getPort() . "
";

    }

});


이 예제에서는 `MongoDBClient`를 사용하여 MongoDB 서버와의 연결을 설정하고, `MongoDBDriverMonitoringServerMonitor`를 사용하여 이벤트를 등록합니다. `ServerChangedEventInterface`를 구현하는 클래스를 사용하여 이벤트를 수신하고, 이전에 연결된 MongoDB 서버의 설명을 가져옵니다.

결과

이 예제를 실행하면 다음과 같은 결과가 출력됩니다.
#hostingforum.kr


이전 연결된 MongoDB 서버의 설명: localhost:27017

현재 연결된 MongoDB 서버의 설명: localhost:27017


이 예제는 `MongoDBDriverMonitoringServerChangedEvent`를 사용하여 이전에 연결된 MongoDB 서버의 설명을 가져오는 방법을 보여줍니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색