<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.snmp.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'snmp.set.php',
    1 => 'SNMP::set',
    2 => 'Set the value of an SNMP object',
  ),
  'up' => 
  array (
    0 => 'class.snmp.php',
    1 => 'SNMP',
  ),
  'prev' => 
  array (
    0 => 'snmp.getnext.php',
    1 => 'SNMP::getnext',
  ),
  'next' => 
  array (
    0 => 'snmp.setsecurity.php',
    1 => 'SNMP::setSecurity',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/snmp/snmp/set.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="snmp.set" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SNMP::set</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.4.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">SNMP::set</span> &mdash; <span class="dc-title">Set the value of an SNMP object</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-snmp.set-description">
  <h3 class="title">Description</h3>

  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SNMP::set</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$objectId</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$type</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="simpara">
   Requests remote <abbr title="Simple Network Management Protocol">SNMP</abbr> agent setting the value of
   one or more SNMP objects specified by the <code class="parameter">objectId</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-snmp.set-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   <p class="simpara">
    If <code class="parameter">objectId</code> is <span class="type"><a href="language.types.string.php" class="type string">string</a></span>, both
    <code class="parameter">type</code> and <code class="parameter">value</code> must be
    <span class="type"><a href="language.types.string.php" class="type string">string</a></span> too. If <code class="parameter">objectId</code> is <span class="type"><a href="language.types.array.php" class="type array">array</a></span>
    <code class="parameter">value</code> must be equal-sized array containing
    corresponding values, <code class="parameter">type</code> may be either
    <span class="type"><a href="language.types.string.php" class="type string">string</a></span> (it&#039;s value will be used for all
    <code class="parameter">objectId</code>-<code class="parameter">value</code> pairs) or
    equal-sized array with per-OID value. When any other parameters&#039; combinations are
    used, a number of E_WARNING messages may be shown with detailed description.
   </p>
   
    <dt><code class="parameter">objectId</code></dt>
    <dd>
     <span class="simpara">
      The SNMP object id
     </span>
     <span class="simpara">
      When count of OIDs in object_id array is greater than
      max_oids object property set method will have to use multiple queries
      to perform requested value updates. In this case type and value checks
      are made per-chunk so second or subsequent requests may fail due to
      wrong type or value for OID requested. To mark this a warning is
      raised when count of OIDs in object_id array is greater than max_oids.
     </span>
    </dd>
   
   
    <dt><code class="parameter">type</code></dt>
    <dd>
     <p class="para">
 The <abbr>MIB</abbr> defines the type of each object id. It has to be specified as a single character from the below list.
</p>
<table class="doctable table">
 <caption><strong>types</strong></caption>
 
  <tbody class="tbody">
   <tr><td>=</td><td>The type is taken from the MIB</td></tr>

   <tr><td>i</td><td>INTEGER</td> </tr>

   <tr><td>u</td><td>INTEGER</td></tr>

   <tr><td>s</td><td>STRING</td></tr>

   <tr><td>x</td><td>HEX STRING</td></tr>

   <tr><td>d</td><td>DECIMAL STRING</td></tr>

   <tr><td>n</td><td>NULLOBJ</td></tr>

   <tr><td>o</td><td>OBJID</td></tr>

   <tr><td>t</td><td>TIMETICKS</td></tr>

   <tr><td>a</td><td>IPADDRESS</td></tr>

   <tr><td>b</td><td>BITS</td></tr>

  </tbody>
 
</table>

<p class="para">
 If <strong><code>OPAQUE_SPECIAL_TYPES</code></strong> was defined while compiling the <abbr title="Simple Network Management Protocol">SNMP</abbr> library, the following are also valid:
</p>
<table class="doctable table">
 <caption><strong>types</strong></caption>
 
  <tbody class="tbody">
   <tr><td>U</td><td>unsigned int64</td></tr>

   <tr><td>I</td><td>signed int64</td></tr>

   <tr><td>F</td><td>float</td></tr>

   <tr><td>D</td><td>double</td></tr>

  </tbody>
 
</table>


     <p class="para">
 Most of these will use the obvious corresponding ASN.1 type.  &#039;s&#039;, &#039;x&#039;, &#039;d&#039; and &#039;b&#039; are all different ways of specifying an OCTET STRING value, and
 the &#039;u&#039; unsigned type is also used for handling Gauge32 values.
</p>

     <p class="para">
 If the MIB-Files are loaded by into the MIB Tree with &quot;snmp_read_mib&quot; or by specifying it in the libsnmp config, &#039;=&#039; may be used as
 the <code class="parameter">type</code> parameter for all object ids as the type can then be automatically read from the MIB.
</p>

     <p class="para">
 Note that there are two ways to set a variable of the type BITS like e.g.
 &quot;SYNTAX    BITS {telnet(0), ftp(1), http(2), icmp(3), snmp(4), ssh(5), https(6)}&quot;:
</p>
<ul class="itemizedlist">
 <li class="listitem">
  <span class="simpara">
   Using type &quot;b&quot; and a list of bit numbers. This method is not recommended since GET query for the same OID would return e.g. 0xF8.
  </span>
 </li>
 <li class="listitem">
  <span class="simpara">
   Using type &quot;x&quot; and a hex number but without(!) the usual &quot;0x&quot; prefix.
  </span>
 </li>
</ul>
<p class="para">
 See examples section for more details.
</p>

    </dd>
   
   
    <dt><code class="parameter">value</code></dt>
    <dd>
     <span class="simpara">
      The new value.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-snmp.set-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="simpara">
   Returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> on success or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-snmp.set-errors">
<h3 class="title">Errors/Exceptions</h3>
<p class="para">
 This method does not throw any exceptions by default.
 To enable throwing an SNMPException exception when some of library errors occur
 the SNMP class parameter <code class="parameter">exceptions_enabled</code>
 should be set to a corresponding value. See <a href="class.snmp.php#snmp.props.exceptions-enabled" class="link">
 <code class="parameter">SNMP::$exceptions_enabled</code> explanation</a> for more details.
</p>
</div>



 <div class="refsect1 examples" id="refsect1-snmp.set-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="snmp.set.example.basic">
   <p><strong>Example #1 Set single <abbr title="Simple Network Management Protocol">SNMP</abbr> object id</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />  $session </span><span style="color: #007700">= new </span><span style="color: #0000BB">SNMP</span><span style="color: #007700">(</span><span style="color: #0000BB">SNMP</span><span style="color: #007700">::</span><span style="color: #0000BB">VERSION_2C</span><span style="color: #007700">, </span><span style="color: #DD0000">"127.0.0.1"</span><span style="color: #007700">, </span><span style="color: #DD0000">"private"</span><span style="color: #007700">);<br />  </span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #DD0000">'SNMPv2-MIB::sysContact.0'</span><span style="color: #007700">, </span><span style="color: #DD0000">'s'</span><span style="color: #007700">, </span><span style="color: #DD0000">"Nobody"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
  <div class="example" id="snmp.set.example.multiple">
   <p><strong>Example #2 Set multiple values using single <span class="methodname"><strong>SNMP::set()</strong></span>
   call</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />  $session </span><span style="color: #007700">= new </span><span style="color: #0000BB">SNMP</span><span style="color: #007700">(</span><span style="color: #0000BB">SNMP</span><span style="color: #007700">::</span><span style="color: #0000BB">VERSION_2C</span><span style="color: #007700">, </span><span style="color: #DD0000">"127.0.0.1"</span><span style="color: #007700">, </span><span style="color: #DD0000">"private"</span><span style="color: #007700">);<br />  </span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'SNMPv2-MIB::sysContact.0'</span><span style="color: #007700">, </span><span style="color: #DD0000">'SNMPv2-MIB::sysLocation.0'</span><span style="color: #007700">), array(</span><span style="color: #DD0000">'s'</span><span style="color: #007700">, </span><span style="color: #DD0000">'s'</span><span style="color: #007700">), array(</span><span style="color: #DD0000">"Nobody"</span><span style="color: #007700">, </span><span style="color: #DD0000">"Nowhere"</span><span style="color: #007700">));<br /></span><span style="color: #FF8000">// or<br />  </span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'SNMPv2-MIB::sysContact.0'</span><span style="color: #007700">, </span><span style="color: #DD0000">'SNMPv2-MIB::sysLocation.0'</span><span style="color: #007700">), </span><span style="color: #DD0000">'s'</span><span style="color: #007700">, array(</span><span style="color: #DD0000">"Nobody"</span><span style="color: #007700">, </span><span style="color: #DD0000">"Nowhere"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
   <div class="example" id="snmp.set.example.bits">
    <p><strong>Example #3 Using <span class="methodname"><strong>SNMP::set()</strong></span> for setting BITS <abbr title="Simple Network Management Protocol">SNMP</abbr> object id</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />  $session </span><span style="color: #007700">= new </span><span style="color: #0000BB">SNMP</span><span style="color: #007700">(</span><span style="color: #0000BB">SNMP</span><span style="color: #007700">::</span><span style="color: #0000BB">VERSION_2C</span><span style="color: #007700">, </span><span style="color: #DD0000">"127.0.0.1"</span><span style="color: #007700">, </span><span style="color: #DD0000">"private"</span><span style="color: #007700">);<br />  </span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #DD0000">'FOO-MIB::bar.42'</span><span style="color: #007700">, </span><span style="color: #DD0000">'b'</span><span style="color: #007700">, </span><span style="color: #DD0000">'0 1 2 3 4'</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// or<br />  </span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #DD0000">'FOO-MIB::bar.42'</span><span style="color: #007700">, </span><span style="color: #DD0000">'x'</span><span style="color: #007700">, </span><span style="color: #DD0000">'F0'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-snmp.set-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="methodname"><a href="snmp.get.php" class="methodname" rel="rdfs-seeAlso">SNMP::get()</a> - Fetch an SNMP object</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>