@@ -89,6 +89,8 @@ typedef struct snmp_session php_snmp_session;
8989 } \
9090}
9191
92+ static int mib_needs_reset ;
93+
9294ZEND_DECLARE_MODULE_GLOBALS (snmp )
9395static PHP_GINIT_FUNCTION (snmp );
9496
@@ -1629,6 +1631,7 @@ PHP_FUNCTION(snmp_read_mib)
16291631 RETURN_THROWS ();
16301632 }
16311633
1634+ mib_needs_reset = 1 ;
16321635 if (!read_mib (filename )) {
16331636 char * error = strerror (errno );
16341637 php_error_docref (NULL , E_WARNING , "Error while reading MIB file '%s': %s" , filename , error );
@@ -1638,6 +1641,27 @@ PHP_FUNCTION(snmp_read_mib)
16381641}
16391642/* }}} */
16401643
1644+ /* {{{ Resets the MIB tree and set the mib directories to the provided mibdirs. */
1645+ PHP_FUNCTION (snmp_init_mib )
1646+ {
1647+ zend_string * mibdirs = NULL ;
1648+
1649+ ZEND_PARSE_PARAMETERS_START (0 , 1 )
1650+ Z_PARAM_OPTIONAL
1651+ Z_PARAM_STR_OR_NULL (mibdirs )
1652+ ZEND_PARSE_PARAMETERS_END ();
1653+
1654+ // If the mibdirs has been changed, we need to reset the MIB tree at the end of the request
1655+ if (mibdirs != NULL ) {
1656+ mib_needs_reset = 1 ;
1657+ }
1658+
1659+ shutdown_mib ();
1660+ netsnmp_ds_set_string (NETSNMP_DS_LIBRARY_ID , NETSNMP_DS_LIB_MIBDIRS , ZSTR_VAL (mibdirs ));
1661+ init_mib ();
1662+ }
1663+ /* }}} */
1664+
16411665/* {{{ Creates a new SNMP session to specified host. */
16421666PHP_METHOD (SNMP , __construct )
16431667{
@@ -2172,6 +2196,19 @@ PHP_MSHUTDOWN_FUNCTION(snmp)
21722196}
21732197/* }}} */
21742198
2199+ /* {{{ PHP_RSHUTDOWN_FUNCTION */
2200+ static PHP_RSHUTDOWN_FUNCTION (snmp )
2201+ {
2202+ if (mib_needs_reset ) {
2203+ shutdown_mib ();
2204+ netsnmp_ds_set_string (NETSNMP_DS_LIBRARY_ID , NETSNMP_DS_LIB_MIBDIRS , NULL );
2205+ init_mib ();
2206+ }
2207+
2208+ return SUCCESS ;
2209+ }
2210+ /* }}} */
2211+
21752212/* {{{ PHP_MINFO_FUNCTION */
21762213PHP_MINFO_FUNCTION (snmp )
21772214{
@@ -2199,7 +2236,7 @@ zend_module_entry snmp_module_entry = {
21992236 PHP_MINIT (snmp ),
22002237 PHP_MSHUTDOWN (snmp ),
22012238 NULL ,
2202- NULL ,
2239+ PHP_RSHUTDOWN ( snmp ) ,
22032240 PHP_MINFO (snmp ),
22042241 PHP_SNMP_VERSION ,
22052242 PHP_MODULE_GLOBALS (snmp ),
0 commit comments