라이브러리

[PHP] MongoDBDriverMonitoringCommandFailedEvent::getHost - 명령에 대한 서버 호스트 이름을 반환합니다.




MongoDB Driver Monitoring Command Failed Event

MongoDB Driver Monitoring Command Failed Event는 MongoDB Driver에서 발생하는 이벤트 중 하나입니다. 이 이벤트는 MongoDB와의 연결이 실패했을 때 발생하며, 실패한 명령어의 정보를 포함합니다.

getHost() 메서드

getHost() 메서드는 MongoDB Driver Monitoring Command Failed Event에서 발생한 실패한 명령어의 호스트 이름을 반환합니다.

예제

아래 예제는 PHP에서 MongoDB Driver Monitoring Command Failed Event를 사용하는 방법을 보여줍니다.

#hostingforum.kr
php

use MongoDBDriverMonitoringCommandFailedEvent;



// MongoDB 연결 설정

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



// MongoDB Driver Monitoring Command Failed Event 리스너 등록

$manager->addCommandListener(new class extends MongoDBDriverMonitoringCommandFailedEvent {

    public function __invoke(CommandFailedEvent $event) {

        // getHost() 메서드 사용

        echo "호스트 이름: " . $event->getHost() . "
";

        echo "실패한 명령어: " . $event->getCommand()->getCmd() . "
";

        echo "실패한 이유: " . $event->getException()->getMessage() . "
";

    }

});



// MongoDB에 연결

$manager->execute(new MongoDBDriverCommand(["ping" => 1]));



// MongoDB와의 연결을 끊습니다.

$manager->close();



이 예제에서는 MongoDB Driver Monitoring Command Failed Event 리스너를 등록하고, MongoDB와의 연결을 끊는 과정을 보여줍니다. 실패한 명령어의 호스트 이름, 실패한 명령어, 실패한 이유를 출력합니다.

주의

MongoDB Driver Monitoring Command Failed Event는 MongoDB와의 연결이 실패했을 때 발생합니다. 따라서 MongoDB와의 연결을 끊는 경우 이 이벤트가 발생합니다. MongoDB와의 연결을 끊기 전에 이벤트 리스너를 등록해야 합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색