라이브러리
[PHP] MongoDBDriverMonitoringCommandStartedEvent::getCommandName - 명령 이름을 반환합니다.
MongoDB Driver Monitoring Command Started Event
MongoDB Driver Monitoring Command Started Event는 MongoDB Driver에서 발생하는 이벤트 중 하나입니다. 이 이벤트는 MongoDB 커맨드가 시작될 때 발생하며, 커맨드의 이름을 포함한 다양한 정보를 제공합니다.
MongoDBDriverMonitoringCommandStartedEvent::getCommandName
`getCommandName` 메소드는 MongoDB 커맨드의 이름을 반환합니다. 이 메소드는 `MongoDBDriverMonitoringCommandStartedEvent` 객체를 통해 호출할 수 있으며, 커맨드의 이름을 문자열로 반환합니다.
예제
다음 예제는 MongoDB Driver Monitoring Command Started Event를 사용하여 커맨드의 이름을 가져오는 방법을 보여줍니다.
#hostingforum.kr
php
use MongoDBDriverMonitoringCommandStartedEvent;
use MongoDBDriverMonitoringCommandStartedData;
// MongoDB 커넥션을 생성합니다.
$manager = new MongoDBDriverManager('mongodb://localhost:27017');
// 커맨드 시작 이벤트 리스너를 등록합니다.
$manager->addCommandListener(
function (CommandStartedEvent $event) {
// 커맨드 이름을 가져옵니다.
$commandName = $event->getCommandName();
// 커맨드 이름을 출력합니다.
echo "커맨드 이름: $commandName
";
}
);
// MongoDB 데이터베이스에 커맨드를 실행합니다.
$command = new MongoDBDriverCommand(['find' => 'users']);
$manager->executeCommand('mydatabase', $command);
이 예제에서는 MongoDB 커넥션을 생성하고 커맨드 시작 이벤트 리스너를 등록합니다. 커맨드 시작 이벤트가 발생할 때, 리스너 함수는 커맨드 이름을 가져와 출력합니다. 이 예제에서는 `find` 커맨드를 실행하여 커맨드 이름을 가져옵니다.
결론
MongoDB Driver Monitoring Command Started Event는 MongoDB 커맨드가 시작될 때 발생하는 이벤트입니다. `getCommandName` 메소드는 커맨드의 이름을 반환하며, 커맨드 시작 이벤트 리스너를 등록하여 커맨드 이름을 가져올 수 있습니다. 이 예제는 커맨드 시작 이벤트 리스너를 등록하고 커맨드 이름을 가져오는 방법을 보여줍니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.