array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'es', ), 'this' => array ( 0 => 'function.inotify-init.php', 1 => 'inotify_init', ), 'up' => array ( 0 => 'ref.inotify.php', 1 => 'Funciones 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' => 'es', 'path' => 'reference/inotify/functions/inotify-init.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PECL inotify >= 0.1.2)
inotify_init — Inicializa una instancia inotify
Inicializar una instancia inotify para usar con inotify_add_watch()
Esta función no tiene parámetros.
Un recurso de secuencia o false
en caso de error.
Ejemplo #1 Ejemplo de uso de inotify
<?php
// Abrir una instancia inotify
$fd = inotify_init();
// Observar __FILE__ por cambios en los metadatos (por ejemplo: mtime)
$watch_descriptor = inotify_add_watch($fd, __FILE__, IN_ATTRIB);
// genera un evento
touch(__FILE__);
// Leer eventos
$eventos = inotify_read($fd);
print_r($eventos);
// Los siguientes métodos permiten utilizar funciones inotify sin bloqueo en inotify_read():
// - Usando stream_select() en $fd:
$read = array($fd);
$write = null;
$except = null;
stream_select($read,$write,$except,0);
// - Usando stream_set_blocking() en $fd
stream_set_blocking($fd, 0);
inotify_read($fd); // No hace ningún bloqueo, y devuelve false si no hay eventos pendientes
// - Usando inotify_queue_len() para comprobar si la lista de eventos no está vacía
$queue_len = inotify_queue_len($fd); // Si > 0, inotify_read() no bloqueará
// Dejar de observar __FILE__ por cambios en los metadatos
inotify_rm_watch($fd, $watch_descriptor);
// Cierra la instancia inotify
// This may have closed all watches if this was not already done
// Esto puede haber cerrado todos los seguimientos, si no se hizo ya
fclose($fd);
?>
El resultado del ejemplo sería algo similar a:
array( array( 'wd' => 1, // Equivale a $ watch_descriptor 'mask' => 4, // bit IN_ATTRIB establecido 'cookie' => 0, // id único para conectar los eventos relacionados (por ejemplo: // eventos IN_MOVE_FROM IN_MOVE_TO) 'name' => '', // el nombre de un fichero (por ejemplo: si se monitorean los // cambios en un directorio) ), );