라이브러리

[PHP] MongoDBDriverMonitoringCommandStartedEvent::getServer - 명령이 실행된 서버를 반환합니다.




MongoDB Driver Monitoring Command Started Event

MongoDB Driver Monitoring Command Started Event는 MongoDB Driver의 Monitoring 기능을 통해 발생하는 이벤트 중 하나입니다. 이 이벤트는 MongoDB 서버와의 통신이 시작되었을 때 발생하며, 이 이벤트를 통해 MongoDB 서버의 정보를 얻을 수 있습니다.

MongoDBDriverMonitoringCommandStartedEvent 클래스

`MongoDBDriverMonitoringCommandStartedEvent` 클래스는 `MongoDBDriverMonitoringEvent` 클래스를 상속받은 클래스로, MongoDB 서버와의 통신이 시작되었을 때 발생하는 이벤트를 나타냅니다.

getServer() 메서드

`getServer()` 메서드는 MongoDB 서버의 정보를 반환하는 메서드입니다. 이 메서드는 `MongoDBServer` 객체를 반환하며, MongoDB 서버의 이름, 호스트, 포트, 및 기타 정보를 포함합니다.

예제

다음 예제는 `MongoDBDriverMonitoringCommandStartedEvent` 클래스의 `getServer()` 메서드를 사용하는 방법을 보여줍니다.

#hostingforum.kr
php

use MongoDBDriverMonitoringCommandStartedEvent;

use MongoDBDriverMonitoringEvent;

use MongoDBDriverMonitoringServer;



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

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



// MongoDB 서버와의 통신이 시작되었을 때 발생하는 이벤트를 등록합니다.

$manager->addCommandStartedEventListener(function (Event $event) {

    if ($event instanceof CommandStartedEvent) {

        // MongoDB 서버의 정보를 얻습니다.

        $server = $event->getServer();

        

        // MongoDB 서버의 이름을 출력합니다.

        echo "서버 이름: " . $server->getName() . "
";

        

        // MongoDB 서버의 호스트를 출력합니다.

        echo "서버 호스트: " . $server->getHost() . "
";

        

        // MongoDB 서버의 포트를 출력합니다.

        echo "서버 포트: " . $server->getPort() . "
";

    }

});



// MongoDB 서버와의 통신을 시작합니다.

$manager->executeCommand('test', new MongoDBBSONUTCDateTime());



이 예제에서는 `MongoDBDriverMonitoringCommandStartedEvent` 클래스의 `getServer()` 메서드를 사용하여 MongoDB 서버의 정보를 얻습니다. `addCommandStartedEventListener()` 메서드를 사용하여 MongoDB 서버와의 통신이 시작되었을 때 발생하는 이벤트를 등록하고, `executeCommand()` 메서드를 사용하여 MongoDB 서버와의 통신을 시작합니다.

이 예제는 MongoDB 서버의 이름, 호스트, 포트를 출력하는 예제입니다. MongoDB 서버의 정보를 얻는 방법을 보여주며, MongoDB Driver Monitoring 기능을 사용하는 방법을 보여줍니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색