<?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 => 'uk',
  ),
  '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 Функції',
  ),
  '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">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">function</span> <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">Параметри</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">
 <abbr>MIB</abbr> дає означення типу для ID об&#039;єкта. Тип можна
 вказувати одним з символів:
</p>
<table class="doctable table">
 <caption><strong>types</strong></caption>
 
  <tbody class="tbody">
   <tr><td>=</td><td>Тип, взятий з 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">
 Якщо під час компіляції бібліотеки <abbr title="Simple Network Management Protocol">SNMP</abbr> задано
<strong><code>OPAQUE_SPECIAL_TYPES</code></strong>, будуть доступні наступні типи:
</p>
<table class="doctable table">
 <caption><strong>types</strong></caption>
 
  <tbody class="tbody">
   <tr><td>U</td><td>беззнаковий int64</td></tr>

   <tr><td>I</td><td>знаковий int64</td></tr>

   <tr><td>F</td><td>десятковий дріб (float)</td></tr>

   <tr><td>D</td><td>десятковий дріб подвійної точності (double)</td></tr>

  </tbody>
 
</table>


     <p class="para">
 Більшість з них мають зрозумілий ASN.1-тип. &quot;s&quot;, &quot;x&quot;, &quot;d&quot; та &quot;b&quot; вказують на
 один тип — OCTET STRING, а беззнаковий тип &quot;u&quot; використовується для обробки
 значень Gauge32.
</p>

     <p class="para">
 Якщо MIB-файли підключені до дерева MIB, бо вказані в налаштуваннях libsnmp або
 за допомогою &quot;snmp_read_mib&quot;, то потрібно задавати параметр
 <code class="parameter">type</code> зі значенням &quot;=&quot; для усіх ID об&#039;єктів,
 оскільки тип можна автоматично зчитувати з MIB.
</p>

     <p class="para">
 Варто зазначити, що є два способи задати значення змінній, яка має тип BITS, як
 от &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">
   Використавши тип &quot;b&quot; та список бітових чисел. Цей спосіб не рекомендований,
   оскільки на GET-запит для однакових OID може бути відповідь, напр., 0xF8.
  </span>
 </li>
 <li class="listitem">
  <span class="simpara">
   Використавши тип &quot;x&quot; та шістнадцяткове число, проте без(!) звичного префікса
   &quot;0x&quot;.
  </span>
 </li>
</ul>
<p class="para">
 Докладніше це описано у параграфі з прикладами.
</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">Значення, що повертаються</h3>
  <p class="simpara">
   Повертає <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> у разі успіху або <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> в разі помилки.
  </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">Журнал змін</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Версія</th>
      <th>Опис</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">Приклади</h3>
   <div class="example" id="example-1">
    <p><strong>Приклад #1 Using <span class="function"><strong>snmp2_set()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
  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">);
</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
    </div>

   </div>
   <div class="example" id="example-2">
    <p><strong>Приклад #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"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
  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">);
</span><span style="color: #FF8000">// or
  </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">);
</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
    </div>

   </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.snmp2-set-seealso">
  <h3 class="title">Прогляньте також</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); ?>