라이브러리
[PHP] MongoDBDriverMonitoringCommandStartedEvent::getServerConnectionId - 명령에 대한 서버 연결 ID를 반환합니다.
MongoDB Driver Monitoring Command Started Event
MongoDB Driver Monitoring Command Started Event는 MongoDB Driver가 실행되는 동안 발생하는 이벤트 중 하나입니다. 이 이벤트는 MongoDB Driver가 새로운 명령을 시작할 때 발생합니다. 이 이벤트를 사용하여 MongoDB Driver의 동작을 모니터링하고 분석할 수 있습니다.
MongoDBDriverMonitoringCommandStartedEvent::getServerConnectionId
`getServerConnectionId` 메소드는 MongoDB Driver가 현재 연결된 서버의 Connection ID를 반환하는 메소드입니다. 이 메소드는 `MongoDBDriverMonitoringCommandStartedEvent` 객체의 속성 중 하나입니다.
예제
아래 예제는 `MongoDBDriverMonitoringCommandStartedEvent` 객체의 `getServerConnectionId` 메소드를 사용하는 방법을 보여줍니다.
#hostingforum.kr
php
use MongoDBDriverMonitoringCommandStartedEvent;
use MongoDBDriverMonitoringCommandStartedEventSubscriber;
use MongoDBDriverServer;
// MongoDB Driver를 초기화합니다.
$manager = new MongoDBDriverManager("mongodb://localhost:27017");
// CommandStartedEventSubscriber를 생성합니다.
$subscriber = new CommandStartedEventSubscriber();
// CommandStartedEvent를 수신하기 위해 subscribe합니다.
$manager->addCommandStartedEventListener($subscriber);
// MongoDB Driver가 새로운 명령을 시작할 때 발생하는 이벤트를 수신합니다.
$subscriber->onCommandStarted = function(CommandStartedEvent $event) {
// 현재 연결된 서버의 Connection ID를 가져옵니다.
$connectionId = $event->getServerConnectionId();
// Connection ID를 출력합니다.
echo "Connection ID: $connectionId
";
};
// MongoDB Driver가 새로운 명령을 시작합니다.
$manager->executeCommand(new MongoDBBSONUTCDateTime());
결과
이 예제를 실행하면 MongoDB Driver가 새로운 명령을 시작할 때 발생하는 이벤트를 수신하고, 현재 연결된 서버의 Connection ID를 출력합니다.
참고
* MongoDB Driver Monitoring Command Started Event:
* MongoDB Driver Monitoring Command Started Event Subscriber:
* MongoDB Driver:
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.