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

contributors($setup);

?>
<div id="function.snmp2-set" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">snmp2_set</h1>
  <p class="verinfo">(PHP &gt;= 5.2.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">snmp2_set</span> &mdash; <span class="dc-title">Set the value of an <abbr title="Simple Network Management Protocol">SNMP</abbr> object</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.snmp2-set-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>snmp2_set</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$hostname</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$community</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<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">$object_id</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<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>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<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>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$timeout</code><span class="initializer"> = -1</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$retries</code><span class="initializer"> = -1</span></span><br>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="simpara">
   <span class="function"><strong>snmp2_set()</strong></span> is used to set the value of an <abbr title="Simple Network Management Protocol">SNMP</abbr> object
   specified by the <code class="parameter">object_id</code>.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.snmp2-set-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <dl>
   
    <dt><code class="parameter">hostname</code></dt>
    <dd>
     <span class="simpara">
      The hostname of the <abbr title="Simple Network Management Protocol">SNMP</abbr> agent (server).
     </span>
    </dd>
   
   
    <dt><code class="parameter">community</code></dt>
    <dd>
     <span class="simpara">
      The write community.
     </span>
    </dd>
   
   
    <dt><code class="parameter">object_id</code></dt>
    <dd>
     <span class="simpara">
      The <abbr title="Simple Network Management Protocol">SNMP</abbr> object id.
     </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>
   
   
    <dt><code class="parameter">timeout</code></dt>
    <dd>
     <span class="simpara">
      The number of microseconds until the first timeout.
     </span>
    </dd>
   
   
    <dt><code class="parameter">retries</code></dt>
    <dd>
     <span class="simpara">
      The number of times to retry if timeouts occur.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.snmp2-set-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="simpara">
   Restituisce <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> in caso di successo, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> in caso di fallimento.
  </p>
  <p class="simpara">
   If the SNMP host rejects the data type, an E_WARNING message like &quot;Warning: Error in packet. Reason: (badValue) The value given has the wrong type or length.&quot; is shown.
   If an unknown or invalid OID is specified the warning probably reads &quot;Could not add variable&quot;.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.snmp2-set-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versione</th>
      <th>Descrizione</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.5.0</td>
      <td>
       Now throws a <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> 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.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.snmp2-set-examples">
  <h3 class="title">Esempi</h3>
   <div class="example" id="example-1">
    <p><strong>Example #1 Using <span class="function"><strong>snmp2_set()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />  snmp2_set</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #DD0000">"public"</span><span style="color: #007700">, </span><span style="color: #DD0000">"IF-MIB::ifAlias.3"</span><span style="color: #007700">, </span><span style="color: #DD0000">"s"</span><span style="color: #007700">, </span><span style="color: #DD0000">"foo"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
   <div class="example" id="example-2">
    <p><strong>Example #2 Using <span class="function"><strong>snmp2_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 />  snmp2_set</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #DD0000">"public"</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">snmp2_set</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #DD0000">"public"</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-function.snmp2-set-seealso">
  <h3 class="title">Vedere anche:</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.snmp2-get.php" class="function" rel="rdfs-seeAlso">snmp2_get()</a> - Fetch an SNMP object</span></li>
  </ul>
 </div>


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