snmpset
(PHP 4, PHP 5, PHP 7, PHP 8)
Set the value of an SNMP object
Description
snmpset() is used to set the value of an SNMP object specified by the object_id.
Parameters
hostnameThe hostname of the SNMP agent (server).
communityThe write community.
object_idThe SNMP object id.
typeValues Mapping Note Note
valueThe new value.
timeoutThe number of microseconds until the first timeout.
retriesThe number of times to retry if timeouts occur.
Return Values
Success
If the SNMP host rejects the data type, an E_WARNING message like "Warning: Error in packet. Reason: (badValue) The value given has the wrong type or length." is shown. If an unknown or invalid OID is specified the warning probably reads "Could not add variable".
Changelog
| Version | Description |
|---|---|
| 8.5.0 | Now throws a ValueError when the hostname length is equal to or greater than 128 bytes, when the port is negative or greater than 65535, or when the timeout or retries values are lower than -1 or too large. |
Examples
Using snmpset()
<?php
snmpset("localhost", "public", "IF-MIB::ifAlias.3", "s", "foo");
?>
Using snmpset() for setting BITS SNMP object id
<?php
snmpset("localhost", "public", 'FOO-MIB::bar.42', 'b', '0 1 2 3 4');
// or
snmpset("localhost", "public", 'FOO-MIB::bar.42', 'x', 'F0');
?>