• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • 位置: php 中文手册 -> php 外部扩展库

    SNMP(网络管理协议)

    重要提示:为了使用 UCD SNMP 包,需要在编译之前将NO_ZEROLENGTH_COMMUNITY定义为1。 在配置 UCD SNMP 之后,编辑config.hacconfig.h,查找NO_ZEROLENGTH_COMMUNITY,将 #define 所在行的注释去掉。修改后应该类似这样:

    #define NO_ZEROLENGTH_COMMUNITY 1
    然后使用 --with-snmp[=DIR] 选项编译 PHP。

    如果在组合 SNMP 命令时看到奇怪的字段错误,那就是因为没有遵从上述说明。如果不想重新编译 UCD SNMP,可以使用 --enable-ucd-snmp-hack 开关编译 PHP 以绕开上述错误。

    Windows 版本在目录mibs中包含了支持 SNMP 的文件。此目录应该移到DRIVE:\usr\mibs,其中 DRIVE 是安装 PHP 所在的盘符,例如c:\usr\mibs

    For my purposes in PHP coding, I have the following SNMP options set, always. These aren't documented very well in PHP's docs, but they make dealing with the SNMP results a LOT easier:
    <?php
    // Return back the numeric OIDs, instead of text strings.
    snmp_set_oid_numeric_print(1);
    // Get just the values.
    snmp_set_quick_print(TRUE);
    // For sequence types, return just the numbers, not the string and numbers.
    snmp_set_enum_print(TRUE); 
    // Don't let the SNMP library get cute with value interpretation. This makes 
    // MAC addresses return the 6 binary bytes, timeticks to return just the integer
    // value, and some other things.
    snmp_set_valueretrieval(SNMP_VALUE_PLAIN); 
    ?>
    

    SNMP类

    (PHP 5 >= 5.4.0, PHP 7)

    SNMP 
    {
    	/* 属性 */
    	public int $max_oids ;
    	public int $valueretrieval ;
    	public bool $quick_print ;
    	public bool $enum_print ;
    	public int $oid_output_format ;
    	public bool $oid_increasing_check ;
    	public int $exceptions_enabled ;
    	public array $info ;
    	/* 方法 */
    	public __construct ( int $version , string $hostname , string $community [, int $timeout = 1000000 [, int $retries = 5 ]] )
    	public close ( void ) : bool
    	public get ( mixed $object_id [, bool $preserve_keys = FALSE ] ) : mixed
    	public getErrno ( void ) : int
    	public getError ( void ) : string
    	public getnext ( mixed $object_id ) : mixed
    	public set ( mixed $object_id , mixed $type , mixed $value ) : bool
    	public setSecurity ( string $sec_level [, string $auth_protocol = [, string $auth_passphrase = [, string $priv_protocol = [, string $priv_passphrase = [, string $contextName = [, string $contextEngineID = ]]]]]] ) : bool
    	public walk ( string $object_id [, bool $suffix_as_key = FALSE [, int $max_repetitions [, int $non_repeaters ]]] ) : array
    	/* 常量 */
    	const integer ERRNO_NOERROR = 0 ;
    	const integer ERRNO_GENERIC = 2 ;
    	const integer ERRNO_TIMEOUT = 4 ;
    	const integer ERRNO_ERROR_IN_REPLY = 8 ;
    	const integer ERRNO_OID_NOT_INCREASING = 16 ;
    	const integer ERRNO_OID_PARSING_ERROR = 32 ;
    	const integer ERRNO_MULTIPLE_SET_QUERIES = 64 ;
    	const integer ERRNO_ANY = 126 ;
    	const integer VERSION_1 = 0 ;
    	const integer VERSION_2C = 1 ;
    	const integer VERSION_2c = 1 ;
    	const integer VERSION_3 = 3 ;
    }