simpod / php-snmp
PHP library for connecting to the SNMP agents using various transports; includes small collection of OIDs
Requires
- php: ^8.4
- php-standard-library/json: ^6.1
- php-standard-library/regex: ^6.1
- psr/log: ^3
Requires (Dev)
- ext-json: *
- ext-snmp: *
- cdn77/coding-standard: ^7.0
- colinodell/psr-testlogger: ^1.0
- nyholm/psr7: ^1.3
- php-http/curl-client: ^2.1
- php-standard-library/phpstan-extension: ^2.1
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^13
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^2.0
- squizlabs/php_codesniffer: ^4.0
- symfony/process: 8.1.10
Suggests
- ext-json: Required for SNMP transport "Api"
- ext-snmp: Required for SNMP transport "Extension"
- psr/http-client: Required for SNMP transport "Api"
- psr/http-factory: Required for SNMP transport "Api"
- symfony/process: Required for default implementation of SNMP transport "Cli"
Provides
None
Conflicts
None
Replaces
None
README
Walk defaults
Configure defaultMaxRepetitions once on ApiSnmpClient, CliSnmpClient, or
ExtensionSnmpClient. It defaults to 20. An omitted or null walk limit uses
the executing client's default; an explicit integer, including 20, overrides it.
use SimPod\PhpSnmp\Transport\ApiSnmpClient; use SimPod\PhpSnmp\Transport\Request; $client = new ApiSnmpClient( $httpClient, $requestFactory, $streamFactory, 'http://snmp-proxy', host: '192.0.2.1', defaultMaxRepetitions: 5, ); $client->walk($oid); // Uses 5. $client->walk($oid, 20); // Uses 20, not the configured default. $client->batch([ 'interfaces' => Request::walk($interfacesOid), // Uses 5. 'sensors' => Request::walk($sensorsOid, 15), // Uses 15. ]);
OidStripper::walk() also inherits the client default. GET and GETNEXT do not use
max repetitions; the CLI transport continues to use ordinary walks for SNMP v1.
FallbackSnmpClient preserves an omitted limit so each attempted client applies
its own default. Configure the same default on each client for consistent retries.
Requests are not changed when a client applies its default, so a request can be
reused with another client.
Migrating custom clients (breaking change)
Implementations of SnmpClient must accept
walk(string $oid, int|null $maxRepetitions = null): array. Resolve null to the
client default only when executing the walk. Decorators must preserve null
rather than replace it with 20 or cast it to 0.
Request::walk($oid)->maxRepetitions is now null, not 20. Consumers that read
this property directly must apply the client default when it is null. Existing
callers that omit the limit still use 20 on unconfigured clients.