Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

inotify_init(3) [php man page]

INOTIFY_INIT(3) 							 1							   INOTIFY_INIT(3)

inotify_init - Initialize an inotify instance

SYNOPSIS
resource inotify_init (void ) DESCRIPTION
Initialize an inotify instance for use with inotify_add_watch(3) RETURN VALUES
A stream resource or FALSE on error. EXAMPLES
Example #1 Example usage of inotify <?php // Open an inotify instance $fd = inotify_init(); // Watch __FILE__ for metadata changes (e.g. mtime) $watch_descriptor = inotify_add_watch($fd, __FILE__, IN_ATTRIB); // generate an event touch(__FILE__); // Read events $events = inotify_read($fd); print_r($events); // The following methods allows to use inotify functions without blocking on inotify_read(): // - Using stream_select() on $fd: $read = array($fd); $write = null; $except = null; stream_select($read,$write,$except,0); // - Using stream_set_blocking() on $fd stream_set_blocking($fd, 0); inotify_read($fd); // Does no block, and return false if no events are pending // - Using inotify_queue_len() to check if event queue is not empty $queue_len = inotify_queue_len($fd); // If > 0, inotify_read() will not block // Stop watching __FILE__ for metadata changes inotify_rm_watch($fd, $watch_descriptor); // Close the inotify instance // This may have closed all watches if this was not already done fclose($fd); ?> The above example will output something similar to: array( array( 'wd' => 1, // Equals $watch_descriptor 'mask' => 4, // IN_ATTRIB bit is set 'cookie' => 0, // unique id to connect related events (e.g. // IN_MOVE_FROM and IN_MOVE_TO events) 'name' => '', // the name of a file (e.g. if we monitored changes // in a directory) ), ); SEE ALSO
inotify_add_watch(3), inotify_rm_watch(3), inotify_queue_len(3), inotify_read(3), fclose(3). PHP Documentation Group INOTIFY_INIT(3)

Check Out this Related Man Page

INOTIFY_INIT(2) 					     Linux Programmer's Manual						   INOTIFY_INIT(2)

NAME
inotify_init, inotify_init1 - initialize an inotify instance SYNOPSIS
#include <sys/inotify.h> int inotify_init(void); int inotify_init1(int flags); DESCRIPTION
inotify_init() initializes a new inotify instance and returns a file descriptor associated with a new inotify event queue. If flags is 0, then inotify_init1() is the same as inotify_init(). The following values can be bitwise ORed in flags to obtain different behavior: IN_NONBLOCK Set the O_NONBLOCK file status flag on the new open file description. Using this flag saves extra calls to fcntl(2) to achieve the same result. IN_CLOEXEC Set the close-on-exec (FD_CLOEXEC) flag on the new file descriptor. See the description of the O_CLOEXEC flag in open(2) for reasons why this may be useful. RETURN VALUE
On success, these system calls return a new file descriptor. On error, -1 is returned, and errno is set to indicate the error. ERRORS
EINVAL (inotify_init1()) An invalid value was specified in flags. EMFILE The user limit on the total number of inotify instances has been reached. ENFILE The system limit on the total number of file descriptors has been reached. ENOMEM Insufficient kernel memory is available. VERSIONS
inotify_init() first appeared in Linux 2.6.13; library support was added to glibc in version 2.4. inotify_init1() was added in Linux 2.6.27; library support was added to glibc in version 2.9. CONFORMING TO
These system calls are Linux-specific. SEE ALSO
inotify_add_watch(2), inotify_rm_watch(2), inotify(7) COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2012-05-04 INOTIFY_INIT(2)
Man Page