[php-src] PR #21452: Add snmp_init_mib function to allow MIB tree to be reset using environment variables
| From: | eskyuu | Date: | Sun, 15 Mar 2026 06:55:01 +0000 |
| Subject: | [php-src] PR #21452: Add snmp_init_mib function to allow MIB tree to be reset using environment variables | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-35228@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/21452
Author: eskyuu
I have been trying to use the PHP SNMP extension in LibreNMS to replace calls to external snmp*
programs. One issue I have come across is that there is no way to clear the MIB tree in the PHP
SNMP extension. It becomes even worse with PHP-FPM where the MIB tree is persistent across
different requests.
The above causes issues when a script wants to do multiple SNMP queries against incompatible MIBs
because there is currently no way to clear the MIB tree and start again.
This PR add a new snmp_init_mib() function that frees up the existing MIB tree and then calls
init_mib(), which will:
- Set the MIB directories according to the
MIBDIRS environment variable
- Load MIBs according to the MIBS environment variable (plus any IMPORTs)
- Load MIB files according to the MIBFILES variable
I have chosen to only expose the one function above because the other functions like shutdown_mib(),
init_mib_internals() netsnmp_read_module() require understanding how the net-snmp internals work to
ensure everything is initialised properly. The proposed function can be used to clear the MIB tree
back to the default state if the environment variables are not changed, or to reset to a known state
if the environment variables are updated.
It's marked as draft until I have tested that it works.