tufanbarisyildirim / react-inotify by tufan
forked from mkraemer/react-inotify

Inotify bindings for ReactPHP (forked from mkraemer/react-inotify)
40
0
2
Package Data
Maintainer Username: tufan
Maintainer Contact: tufanbarisyildirim@gmil.com (Tufan Baris YILDIRIM)
Package Create Date: 2014-11-15
Package Last Update: 2015-01-09
Language: PHP
License: MIT
Last Refreshed: 2024-11-14 15:14:28
Package Statistics
Total Downloads: 40
Monthly Downloads: 2
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

React-Inotify

Basic inotify bindings for React PHP.

##Install This library requires PHP5.3 and the inotify PECL extension. The best way to install this library is through composer:

{
    "require": {
        "tufanbarisyildirim/react-inotify": "dev-master"
    }
}

Usage

This library provides the Inotify class which takes an event loop and optionally the timer interval in which the inotify events should be checked as constructor arguments. After initializing the class, you can use the add() method to add paths to the list of watched paths. Use the inotify bitmasks to define to which filesystem operations to listen.

<?php

$loop = React\EventLoop\Factory::create();
$inotify = new MKraemer\ReactInotify\Inotify($loop);

$inotify->add('/tmp/', IN_CLOSE_WRITE | IN_CREATE | IN_DELETE);
$inotify->add('/var/log/', IN_CLOSE_WRITE | IN_CREATE | IN_DELETE);

$inotify->on(IN_CLOSE_WRITE, function ($path) {
    echo 'File closed after writing: '.$path.PHP_EOL;
});

$inotify->on(IN_CREATE, function ($path) {
    echo 'File created: '.$path.PHP_EOL;
});

$inotify->on(IN_DELETE, function ($path) {
    echo 'File deleted: '.$path.PHP_EOL;
});

$loop->run();