라이브러리

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




PHP 에서 MongoDBDriverMonitoringCommandStartedEvent::getHost() 메소드는 MongoDB 드라이버의 모니터링 기능을 통해 발생하는 CommandStartedEvent 이벤트에서 호스트 정보를 얻는 방법을 설명합니다.

MongoDBDriverMonitoringCommandStartedEvent


MongoDBDriverMonitoringCommandStartedEvent는 MongoDB 드라이버의 모니터링 기능을 통해 발생하는 이벤트 중 하나입니다. 이 이벤트는 명령이 시작되었을 때 발생하고, 이벤트에 포함된 정보를 통해 명령의 상세 정보를 확인할 수 있습니다.

getHost() 메소드


getHost() 메소드는 CommandStartedEvent 이벤트에서 호스트 정보를 얻는 방법을 제공합니다. 이 메소드는 이벤트에 포함된 호스트 정보를 반환합니다.

예제


아래 예제는 getHost() 메소드를 사용하는 방법을 보여줍니다.

#hostingforum.kr
php

use MongoDBDriverMonitoringCommandStartedEvent;

use MongoDBDriverMonitoringEvent;



// MongoDB 클라이언트 생성

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



// CommandStartedEvent 이벤트 리스너 등록

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

    if ($event instanceof CommandStartedEvent) {

        $host = $event->getHost();

        echo "호스트 정보: $host
";

    }

});



// MongoDB 데이터베이스와 컬렉션에 접근

$db = $client->selectDatabase('test');

$collection = $db->selectCollection('test');



// 명령 실행

$command = new MongoDBBSONDocument(['find' => 'test']);

$cursor = $collection->aggregate($command);



// 명령이 시작되었을 때 CommandStartedEvent 이벤트가 발생합니다.



결과


호스트 정보: localhost:27017

참고


* MongoDB 드라이버의 모니터링 기능은 MongoDB 클라이언트의 `manager()` 메소드를 통해 사용할 수 있습니다.
* CommandStartedEvent 이벤트는 명령이 시작되었을 때 발생하며, 이벤트에 포함된 정보를 통해 명령의 상세 정보를 확인할 수 있습니다.
* getHost() 메소드는 CommandStartedEvent 이벤트에서 호스트 정보를 얻는 방법을 제공합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색