<?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 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.inotify-init.php',
    1 => 'inotify_init',
    2 => 'Initialise une instance inotify',
  ),
  'up' => 
  array (
    0 => 'ref.inotify.php',
    1 => 'Fonctions 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' => 'fr',
    '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">Initialise une instance inotify</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.inotify-init-description">
  <h3 class="title">Description</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">
   Initialise une instance inotify pour utiliser avec la fonction
   <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">Liste de paramètres</h3>
  <p class="para">Cette fonction ne contient aucun paramètre.</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.inotify-init-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="simpara">
   Un flux ou <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> en cas d&#039;erreur.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.inotify-init-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="inotify-init.example.basic">
    <p><strong>Exemple #1 Exemple d&#039;utilisation d&#039;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">// Crée une instance 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">// Surveille les modifications des métadonnées du fichier __FILE__ (p. ex. mtime)<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">// Génère un événement<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">// Lit les événements<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">// Les méthodes suivantes permettent d'utiliser les fonctions inotify sans bloquer sur inotify_read():<br /><br />// - Utiliser stream_select() sur $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">// - Utiliser stream_set_blocking() sur $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">// Does no block, and return false if no events are pending<br /><br />// - Utiliser inotify_queue_len() pour vérifier la taille de la file d'attente<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">// If &gt; 0, inotify_read() will not block<br /><br />// Arrêt de la surveillance de __FILE__<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">// Destruction de l'instance inotify<br />// Cela aurait arrêté toutes les surveillances si ce n'était pas déjà fait<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>Résultat de l&#039;exemple ci-dessus est similaire à :</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">array(
  array(
    &#039;wd&#039; =&gt; 1,     // Égale le $watch_descriptor
    &#039;mask&#039; =&gt; 4,   // Le bit IN_ATTRIB est activé
    &#039;cookie&#039; =&gt; 0, // identifiant unique pour relier des événements (e.g.
                   // IN_MOVE_FROM et IN_MOVE_TO)
    &#039;name&#039; =&gt; &#039;&#039;,  // Le nom du fichier (e.g. si un dossier était sous surveillance)
  ),
);</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.inotify-init-seealso">
  <h3 class="title">Voir aussi</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.inotify-add-watch.php" class="function" rel="rdfs-seeAlso">inotify_add_watch()</a> - Ajoute un point de surveillance &agrave; une instance inotify</span></li>
   <li><span class="function"><a href="function.inotify-rm-watch.php" class="function" rel="rdfs-seeAlso">inotify_rm_watch()</a> - Supprime un point de surveillance d'une instance inotify</span></li>
   <li><span class="function"><a href="function.inotify-queue-len.php" class="function" rel="rdfs-seeAlso">inotify_queue_len()</a> - Retourne le nombre d'&eacute;v&eacute;nements qui sont survenus</span></li>
   <li><span class="function"><a href="function.inotify-read.php" class="function" rel="rdfs-seeAlso">inotify_read()</a> - Lit les &eacute;v&eacute;nements dans une instance inotify</span></li>
   <li><span class="function"><a href="function.fclose.php" class="function" rel="rdfs-seeAlso">fclose()</a> - Ferme un fichier</span></li>
  </ul>
 </div>


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