SNMP SNMP::__construct
(PHP 5 >= 5.4.0, PHP 7, PHP 8)
SNMP::__construct — 원격 SNMP 에이전트에 대한 세션을 나타내는 SNMP 인스턴스 생성
설명
public SNMP::__construct( int $version, string $hostname, string $community, int $timeout = -1, int $retries = -1 )
함수 설명은 여기에 있습니다.
매개변수
version
- SNMP 프로토콜 버전:
SNMP::VERSION_1
,SNMP::VERSION_2C
,SNMP::VERSION_3
. hostname
- SNMP 에이전트.
hostname
은 콜론 뒤에 선택적 SNMP 에이전트 포트 접미사를 붙일 수 있습니다. 포트와 함께 사용하는 경우 IPv6 주소를 대괄호로 묶어야 합니다. FQDN이hostname
에 사용되는 경우 Net-SNMP 엔진이 아닌 php-snmp 라이브러리에 의해 해결됩니다. FQDN을 지정할 때 IPv6 주소를 사용하려면 FQDN을 대괄호로 묶으면 됩니다. 다음은 몇 가지 예입니다.IPv4 with default port 127.0.0.1 IPv6 with default port ::1 or [::1] IPv4 with specific port 127.0.0.1:1161 IPv6 with specific port [::1]:1161 FQDN with default port host.domain FQDN with specific port host.domain:1161 FQDN with default port, force usage of IPv6 address [host.domain] FQDN with specific port, force usage of IPv6 address [host.domain]:1161 community
community
의 목적은 SNMP 버전에 따라 다릅니다.SNMP::VERSION_1 SNMP community SNMP::VERSION_2C SNMP community SNMP::VERSION_3 SNMPv3 securityName timeout
- 첫 번째 시간 초과까지의 마이크로초 수입니다.
retries
- 시간 초과가 발생한 경우 재시도 횟수입니다.
오류/예외
매개변수 개수 또는 유형이 잘못되었거나 알 수 없는 SNMP 프로토콜 버전이 지정된 경우 SNMP::__construct()에서 예외가 발생합니다.
Examples
예제 #1 Fetching sysLocation
<?php
$session = new SNMP(SNMP::VERSION_1, "127.0.0.1", "public");
$sysdescr = $session->get("sysDescr.0");
echo "$sysdescr\n";
?>
위의 예는 다음과 유사한 결과를 출력합니다.
STRING: Test server
기타
- SNMP::close() - SNMP 세션 닫기