inotify_read

(PECL inotify >= 0.1.2)

inotify_readRead events from an inotify instance

Описание

array inotify_read ( resource $inotify_instance )

Read inotify events from an inotify instance.

Список параметров

inotify_instance

Ресурс, возвращаемый inotify_init()

Возвращаемые значения

An array of inotify events or FALSE if no events was pending and inotify_instance is non-blocking. Each event is an array with the following keys:

  • wd is a watch descriptor returned by inotify_add_watch()
  • mask is a bit mask of events
  • cookie is a unique id to connect related events (e.g. IN_MOVE_FROM and IN_MOVE_TO)
  • name is the name of a file (e.g. if a file was modified in a watched directory)

Смотрите также

  • inotify_init() - Initialize an inotify instance
  • stream_select() - Запускает эквивалент системного вызова select() на заданных массивах потоков с таймаутом, указанным параметрами tv_sec и tv_usec
  • stream_set_blocking() - Устанавливает блокирующий/неблокирующий режим на потоке
  • inotify_queue_len() - Return a number upper than zero if there are pending events

Коментарии

<?php

$wd_constants 
= array(
=> array('IN_ACCESS','File was accessed (read)'),
=> array('IN_MODIFY','File was modified'),
=> array('IN_ATTRIB','Metadata changed (e.g. permissions, mtime, etc.)'),
=> array('IN_CLOSE_WRITE','File opened for writing was closed'),
16 => array('IN_CLOSE_NOWRITE','File not opened for writing was closed'),
32 => array('IN_OPEN','File was opened'),
128 => array('IN_MOVED_TO','File moved into watched directory'),
64 => array('IN_MOVED_FROM','File moved out of watched directory'),
256 => array('IN_CREATE','File or directory created in watched directory'),
512 => array('IN_DELETE','File or directory deleted in watched directory'),
1024 => array('IN_DELETE_SELF','Watched file or directory was deleted'),
2048 => array('IN_MOVE_SELF','Watch file or directory was moved'),
24 => array('IN_CLOSE','Equals to IN_CLOSE_WRITE | IN_CLOSE_NOWRITE'),
192 => array('IN_MOVE','Equals to IN_MOVED_FROM | IN_MOVED_TO'),
4095 => array('IN_ALL_EVENTS','Bitmask of all the above constants'),
8192 => array('IN_UNMOUNT','File system containing watched object was unmounted'),
16384 => array('IN_Q_OVERFLOW','Event queue overflowed (wd is -1 for this event)'),
32768 => array('IN_IGNORED','Watch was removed (explicitly by inotify_rm_watch() or because file was removed or filesystem unmounted'),
1073741824 => array('IN_ISDIR','Subject of this event is a directory'),
1073741840 => array('IN_CLOSE_NOWRITE','High-bit: File not opened for writing was closed'),
1073741856 => array('IN_OPEN','High-bit: File was opened'),
1073742080 => array('IN_CREATE','High-bit: File or directory created in watched directory'),
1073742336 => array('IN_DELETE','High-bit: File or directory deleted in watched directory'),
16777216 => array('IN_ONLYDIR','Only watch pathname if it is a directory (Since Linux 2.6.15)'),
33554432 => array('IN_DONT_FOLLOW','Do not dereference pathname if it is a symlink (Since Linux 2.6.15)'),
536870912 => array('IN_MASK_ADD','Add events to watch mask for this pathname if it already exists (instead of replacing mask).'),
2147483648 => array('IN_ONESHOT','Monitor pathname for one event, then remove from watch list.')
);

$path $argv[1];

$fd inotify_init();
stream_set_blocking($fd0);
$watch_descriptor inotify_add_watch($fd$pathIN_ALL_EVENTS);

$poll 0;
while (
true) {
 
$ecount 0;
 
$fcount 0;
 
// Poll for queued events, generated meanwhile
  // Because while (true) { } has some seriously bad mojo
 
sleep(5);
 
$poll++;
 
$events inotify_read($fd);
  if (
$events$ecount count($events);
  echo 
"=== ".date("Y-m-d H:i:s")." inotify poll #$poll contains ".$ecount." events";
  if (
$events) echo ":";
  echo 
"\n";
  if (
$events) {
        foreach (
$events as $event) {
               
$fcount++;
                echo 
"        inotify Event #".$fcount." - Object: ".$event['name'].": ".$wd_constants[$event['mask']][0]." (".$wd_constants[$event['mask']][1].")\n";
        }
  }
}

inotify_rm_watch($fd$watch_descriptor);

fclose($fd);

?>
2013-09-20 14:50:51
http://php5.kiev.ua/manual/ru/function.inotify-read.html
Автор:
once the watch is read, it is removed from the queue.
(inotify_queue_len will return 0)
2014-12-05 18:52:58
http://php5.kiev.ua/manual/ru/function.inotify-read.html

    Поддержать сайт на родительском проекте КГБ