<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.inotify.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'pt_BR',
  ),
  'this' => 
  array (
    0 => 'function.inotify-init.php',
    1 => 'inotify_init',
    2 => 'Inicializa uma inst&acirc;ncia do Inotify',
  ),
  'up' => 
  array (
    0 => 'ref.inotify.php',
    1 => 'Fun&ccedil;&otilde;es de Inotify',
  ),
  'prev' => 
  array (
    0 => 'function.inotify-add-watch.php',
    1 => 'inotify_add_watch',
  ),
  'next' => 
  array (
    0 => 'function.inotify-queue-len.php',
    1 => 'inotify_queue_len',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'pt_BR',
    'path' => 'reference/inotify/functions/inotify-init.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.inotify-init" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">inotify_init</h1>
  <p class="verinfo">(PECL inotify &gt;= 0.1.2)</p><p class="refpurpose"><span class="refname">inotify_init</span> &mdash; <span class="dc-title">Inicializa uma instância do Inotify</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.inotify-init-description">
  <h3 class="title">Descrição</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>inotify_init</strong></span>(): <span class="type"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="simpara">
   Inicializa uma instância do Inotify para uso com
   <span class="function"><a href="function.inotify-add-watch.php" class="function">inotify_add_watch()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.inotify-init-parameters">
  <h3 class="title">Parâmetros</h3>
  <p class="para">Esta função não possui parâmetros.</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.inotify-init-returnvalues">
  <h3 class="title">Valor Retornado</h3>
  <p class="simpara">
   Um recurso de fluxo ou <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> em caso de erro.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.inotify-init-examples">
  <h3 class="title">Exemplos</h3>
  <p class="para">
   <div class="example" id="inotify-init.example.basic">
    <p><strong>Exemplo #1 Exemplo de uso de Inotify</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Abre uma instância Inotify<br /></span><span style="color: #0000BB">$fd </span><span style="color: #007700">= </span><span style="color: #0000BB">inotify_init</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// Monitora __FILE__ para alterações de metadados (por exemplo, data/horário de modificação)<br /></span><span style="color: #0000BB">$watch_descriptor </span><span style="color: #007700">= </span><span style="color: #0000BB">inotify_add_watch</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">, </span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">, </span><span style="color: #0000BB">IN_ATTRIB</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Gera um evento<br /></span><span style="color: #0000BB">touch</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Lê os eventos<br /></span><span style="color: #0000BB">$events </span><span style="color: #007700">= </span><span style="color: #0000BB">inotify_read</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$events</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Os métodos a seguir permitem usar funções Inotify sem bloquear em inotify_read():<br /><br />// - Usando stream_select() em $fd:<br /></span><span style="color: #0000BB">$read </span><span style="color: #007700">= array(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$write </span><span style="color: #007700">= </span><span style="color: #0000BB">null</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$except </span><span style="color: #007700">= </span><span style="color: #0000BB">null</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">stream_select</span><span style="color: #007700">(</span><span style="color: #0000BB">$read</span><span style="color: #007700">,</span><span style="color: #0000BB">$write</span><span style="color: #007700">,</span><span style="color: #0000BB">$except</span><span style="color: #007700">,</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// - Usando stream_set_blocking() em $fd<br /></span><span style="color: #0000BB">stream_set_blocking</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">inotify_read</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">); </span><span style="color: #FF8000">// Não bloqueia e retorna falso se nenhum evento estiver pendente<br /><br />// - Usando inotify_queue_len() para verificar se a fila de eventos não está vazia<br /></span><span style="color: #0000BB">$queue_len </span><span style="color: #007700">= </span><span style="color: #0000BB">inotify_queue_len</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">); </span><span style="color: #FF8000">// Se &gt; 0, inotify_read() não irá bloquear<br /><br />// Encerra o monitoramento __FILE__ para alterações de metadados<br /></span><span style="color: #0000BB">inotify_rm_watch</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">, </span><span style="color: #0000BB">$watch_descriptor</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Fecha a instância do Inotify<br />// Isso pode encerrar todos os monitoramentos se isso ainda não tiver sido feito<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>O exemplo acima produzirá
algo semelhante a:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">array(
  array(
    &#039;wd&#039; =&gt; 1,     // Igual a $watch_descriptor
    &#039;mask&#039; =&gt; 4,   // Bit IN_ATTRIB definido
    &#039;cookie&#039; =&gt; 0, // ID esclusivo para conectar eventos relacionados (ex.:
                   // eventos IN_MOVE_FROM e IN_MOVE_TO)
    &#039;name&#039; =&gt; &#039;&#039;,  // o nome de um arquivo (ex.: se as alterações são monitoradas
                   // em um diretório)
  ),
);</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.inotify-init-seealso">
  <h3 class="title">Veja Também</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.inotify-add-watch.php" class="function" rel="rdfs-seeAlso">inotify_add_watch()</a> - Adiciona um monitoramento a uma inst&acirc;ncia Inotify inicializada</span></li>
   <li><span class="function"><a href="function.inotify-rm-watch.php" class="function" rel="rdfs-seeAlso">inotify_rm_watch()</a> - Remove um monitoramento existente de uma inst&acirc;ncia do Inotify</span></li>
   <li><span class="function"><a href="function.inotify-queue-len.php" class="function" rel="rdfs-seeAlso">inotify_queue_len()</a> - Retorna um n&uacute;mero maior que zero se houver eventos pendentes</span></li>
   <li><span class="function"><a href="function.inotify-read.php" class="function" rel="rdfs-seeAlso">inotify_read()</a> - L&ecirc; eventos de uma inst&acirc;ncia do Inotify</span></li>
   <li><span class="function"><a href="function.fclose.php" class="function" rel="rdfs-seeAlso">fclose()</a> - Fecha um ponteiro de arquivo aberto</span></li>
  </ul>
 </div>


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