php8.5
Home/ Manual/ snmp / functions/ snmp3_set

snmp3_set

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Set the value of an SNMP object

Description

snmp3_set(string $hostname, string $security_name, string $security_level, string $auth_protocol, string $auth_passphrase, string $privacy_protocol, string $privacy_passphrase, array|string $object_id, array|string $type, array|string $value, int $timeout = -1, int $retries = -1): bool

snmp3_set() is used to set the value of an SNMP object specified by the object_id.

The authentication and privacy arguments must always be passed, but their values are ignored when security_level does not use them.

Parameters

hostname

The hostname of the SNMP agent (server).

security_name

Security-name

security_level

Security-level

auth_protocol

Auth-protocol

auth_passphrase

Auth-passphrase

privacy_protocol

Privacy-protocol

privacy_passphrase

Privacy-passphrase

object_id

The SNMP object id.

type

Values Mapping Note Note

value

The new value

timeout

The number of microseconds until the first timeout.

retries

The 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

VersionDescription
8.5.0Now 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 snmp3_set()

php
<?php
  snmp3_set('localhost', 'james', 'authPriv', 'SHA', 'secret007', 'AES', 'secret007', 'IF-MIB::ifAlias.3', 's', "foo");
?>
 

Using snmp3_set() for setting BITS SNMP object id

php
<?php
  snmp3_set('localhost', 'james', 'authPriv', 'SHA', 'secret007', 'AES', 'secret007', 'FOO-MIB::bar.42', 'b', '0 1 2 3 4');
// or
  snmp3_set('localhost', 'james', 'authPriv', 'SHA', 'secret007', 'AES', 'secret007', 'FOO-MIB::bar.42', 'x', 'F0');
?>
 

Source: reference/snmp/functions/snmp3-set.xml · from the official PHP manual (php/doc-en)