[PHP] Getting PHP 8 to use mibs in the mibs folder

Hello,

I am migrating an application from PHP 7.2 to PHP 8. (RHEL 7 to RHEL 9)

In PHP 7.2 this works:

<?php $host = "10.0.1.4"; $com = "redacted"; $oid = "ipRouteMask"; if ($arry = snmprealwalk ($host, $com, $oid)) { } else { echo "Error, could not retrieve a list of routes from $host."; die(); } In PHP 8 it says: PHP Warning: snmprealwalk(): Invalid object identifier: ipRouteMask If I add snmp_read_mib('/usr/share/snmp/mibs/RFC1213-MIB.txt'); the code works normally but we use more than 110 MIB files across dozens of separate scripts. I tried setting this environment variable MIBDIRS=/usr/share/snmp/mibs that seems to do nothing even in php-cli. Does anyone know how to configure PHP to use the mibdir (or make it work like it did in PHP 7?) thank you.

Hi Drew,

Heaven knows it’s been so long that you’ve probably found an answer … I’m not on RHEL (PHP 8.4.5 on macos 12.5) but, in case the behavior is the same, appending to the MIBS env var helped me (at least spared me from a code change specifying MIBs). From my digging around, it looks like my PHP was finding all the MIBS in my MIBDIR but using a default set of files. Specifying MIBS=+ hinted to it to append some extra mibs to the default mibs list for parsing …

MIBS=+RFC1213-MIB:RFC1155-SMI php test.php

If the behavior is the same for your setup, then … I suppose it’s still a bit clunky because you’d have to append all the (hundreds of) MIBS you care about. On my setup, it looks like there are conf files that might house this variable. Maybe something like that would keep from cluttering up your command-line …

Hope you find the solution you’re looking for,
Patty

On Tue, Apr 1, 2025 at 6:53 AM Drew <zerocarbthirty@gmail.com> wrote:

Hello,

I am migrating an application from PHP 7.2 to PHP 8. (RHEL 7 to RHEL 9)

In PHP 7.2 this works:

<?php $host = "10.0.1.4"; $com = "redacted"; $oid = "ipRouteMask"; if ($arry = snmprealwalk ($host, $com, $oid)) { } else { echo "Error, could not retrieve a list of routes from $host."; die(); } In PHP 8 it says: PHP Warning: snmprealwalk(): Invalid object identifier: ipRouteMask If I add snmp_read_mib('/usr/share/snmp/mibs/RFC1213-MIB.txt'); the code works normally but we use more than 110 MIB files across dozens of separate scripts. I tried setting this environment variable MIBDIRS=/usr/share/snmp/mibs that seems to do nothing even in php-cli. Does anyone know how to configure PHP to use the mibdir (or make it work like it did in PHP 7?) thank you.