当前位置: 首页>>代码示例>>PHP>>正文


PHP inotify_init函数代码示例

本文整理汇总了PHP中inotify_init函数的典型用法代码示例。如果您正苦于以下问题:PHP inotify_init函数的具体用法?PHP inotify_init怎么用?PHP inotify_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了inotify_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct()
 {
     $this->inotifyEventMask = IN_ATTRIB | IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE | IN_MOVE_SELF;
     $this->inotify = inotify_init();
     stream_set_blocking($this->inotify, 0);
     $this->tracker = new Tracker($this);
 }
开发者ID:phpguard,项目名称:listen,代码行数:7,代码来源:InotifyAdapter.php

示例2: main_loop

/**
 * Simple tail program using the inotify extension
 * Usage: ./tail.php file
 */
function main_loop($file, $file_fd)
{
    $inotify = inotify_init();
    if ($inotify === false) {
        fprintf(STDERR, "Failed to obtain an inotify instance\n");
        return 1;
    }
    $watch = inotify_add_watch($inotify, $file, IN_MODIFY);
    if ($watch === false) {
        fprintf(STDERR, "Failed to watch file '%s'", $file);
        return 1;
    }
    while (($events = inotify_read($inotify)) !== false) {
        echo "Event received !\n";
        foreach ($events as $event) {
            if (!($event['mask'] & IN_MODIFY)) {
                continue;
            }
            echo stream_get_contents($file_fd);
            break;
        }
    }
    // May not happen
    inotify_rm_watch($inotify, $watch);
    fclose($inotify);
    fclose($file_fd);
    return 0;
}
开发者ID:diesse,项目名称:php7-inotify,代码行数:32,代码来源:tail.php

示例3: watchADir

 function watchADir($path)
 {
     $this->dirs[$path] = $path;
     $this->ifds[$path] = inotify_init();
     $this->wds[$path] = inotify_add_watch($this->ifds[$path], $path, self::DIR_MASK);
     $this->log("add dir {$path} " . print_r($this->dirs, 1) . print_r($this->wds, 1));
 }
开发者ID:google2013,项目名称:StatsCenter,代码行数:7,代码来源:DirByDay.php

示例4: tail

function tail($file, &$pos)
{
    // get the size of the file
    if (!$pos) {
        $pos = filesize($file);
    }
    // Open an inotify instance
    $fd = inotify_init();
    // Watch $file for changes.
    $watch_descriptor = inotify_add_watch($fd, $file, IN_ALL_EVENTS);
    // Loop forever (breaks are below)
    while (true) {
        // Read events (inotify_read is blocking!)
        $events = inotify_read($fd);
        // Loop though the events which occured
        foreach ($events as $event => $evdetails) {
            // React on the event type
            switch (true) {
                // File was modified
                case $evdetails['mask'] & IN_MODIFY:
                    // Stop watching $file for changes
                    inotify_rm_watch($fd, $watch_descriptor);
                    // Close the inotify instance
                    fclose($fd);
                    // open the file
                    $fp = fopen($file, 'r');
                    if (!$fp) {
                        return false;
                    }
                    // seek to the last EOF position
                    fseek($fp, $pos);
                    // read until EOF
                    while (!feof($fp)) {
                        $buf .= fread($fp, 8192);
                    }
                    // save the new EOF to $pos
                    $pos = ftell($fp);
                    // (remember: $pos is called by reference)
                    // close the file pointer
                    fclose($fp);
                    // return the new data and leave the function
                    return $buf;
                    break;
                    // File was moved or deleted
                // File was moved or deleted
                case $evdetails['mask'] & IN_MOVE:
                case $evdetails['mask'] & IN_MOVE_SELF:
                case $evdetails['mask'] & IN_DELETE:
                case $evdetails['mask'] & IN_DELETE_SELF:
                    // Stop watching $file for changes
                    inotify_rm_watch($fd, $watch_descriptor);
                    // Close the inotify instance
                    fclose($fd);
                    // Return a failure
                    return false;
                    break;
            }
        }
    }
}
开发者ID:stawen,项目名称:domovision,代码行数:60,代码来源:knx-function.php

示例5: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $watches = array();
     $in = inotify_init();
     // add watches starting from root directory
     $root = Path::fromRelative('');
     $this->addWatches($in, $root, $watches);
     printf("\nReading for events\n");
     while (true) {
         $events = inotify_read($in);
         foreach ($events as $event) {
             $path = $watches[$event['wd']];
             $expanded = $this->expandMask($event['mask']);
             $eventName = trim(implode(', ', $expanded), ', ');
             // if the event has a name attached, then index that
             if ($event['name']) {
                 $newPathName = $path->getPathname() . '/' . $event['name'];
                 $newPath = new Path($newPathName);
                 Indexer::index($newPath, 1);
                 // this may be a new directory, so add a watch to it anyway
                 if ($newPath->exists() && $newPath->isDir()) {
                     try {
                         $wd = inotify_add_watch($in, $newPath->getPathname(), $this->computedMask);
                         $watches[$wd] = $newPath;
                     } catch (Exception $e) {
                         echo 'Caught exception: ', $e->getMessage(), "\n";
                     }
                 }
             } else {
                 // event must apply to this directory, so index it, 1 level deep
                 Indexer::index($path, 1);
             }
         }
     }
 }
开发者ID:qqueue,项目名称:MangaIndex,代码行数:40,代码来源:WatcherCommand.php

示例6: start

 public function start()
 {
     $this->stop = false;
     $fd = inotify_init();
     $wd = inotify_add_watch($fd, $this->path, IN_ALL_EVENTS);
     $read = [$fd];
     $write = null;
     $except = null;
     stream_select($read, $write, $except, 0);
     stream_set_blocking($fd, 0);
     while (true) {
         if ($this->stop) {
             inotify_rm_watch($fd, $wd);
             return fclose($fd);
         }
         if ($events = inotify_read($fd)) {
             foreach ($events as $details) {
                 if ($details['name']) {
                     $target = rtrim($this->path, '/') . '/' . $details['name'];
                 } else {
                     $target = $this->path;
                 }
                 $file = new \SplFileInfo($target);
                 switch (true) {
                     case $details['mask'] & IN_MODIFY:
                         $this->modify($file);
                         break;
                 }
                 $this->all($file);
             }
         }
     }
 }
开发者ID:mbfisher,项目名称:watch,代码行数:33,代码来源:InotifyWatcher.php

示例7: __construct

 public function __construct()
 {
     $this->inotify = inotify_init();
     if ($this->inotify == false) {
         // fail fast
         die('cannot initialize inotify');
     }
     stream_set_blocking($this->inotify, true);
 }
开发者ID:Ronmi,项目名称:fruit-watchkit,代码行数:9,代码来源:PECLInotify.php

示例8: __construct

 /**
  * Initializes tracker. Creates inotify resource used to track file and directory changes.
  *
  * @throws RuntimeException If inotify extension unavailable
  */
 public function __construct()
 {
     if (!function_exists('inotify_init')) {
         throw new RuntimeException('You must install inotify to be able to use this tracker.');
     }
     $this->inotify = inotify_init();
     stream_set_blocking($this->inotify, 0);
     $this->bag = new CheckerBag($this->inotify);
 }
开发者ID:mgoedecke,项目名称:Lurker,代码行数:14,代码来源:InotifyTracker.php

示例9: init

 /**
  * 初始化
  * @return NULL
  */
 public static function init()
 {
     self::$inotifySuport = extension_loaded('inotify');
     if (!self::$inotifySuport) {
         return null;
     }
     self::$inotifyFd = inotify_init();
     stream_set_blocking(self::$inotifyFd, 0);
     return self::$inotifyFd;
 }
开发者ID:nangong92t,项目名称:go_src,代码行数:14,代码来源:Inotify.php

示例10: add

 /**
  * Adds a path to the list of watched paths
  *
  * @param string  $path      Path to the watched file or directory
  * @param integer $mask      Bitmask of inotify constants
  * @return integer unique watch identifier, can be used to remove() watch later
  */
 public function add($path, $mask)
 {
     if ($this->inotifyHandler === false) {
         // inotifyHandler not started yet => start a new one
         $this->inotifyHandler = \inotify_init();
         stream_set_blocking($this->inotifyHandler, 0);
         // wait for any file events by reading from inotify handler asynchronously
         $this->loop->addReadStream($this->inotifyHandler, $this);
     }
     $descriptor = \inotify_add_watch($this->inotifyHandler, $path, $mask);
     $this->watchDescriptors[$descriptor] = array('path' => $path);
     return $descriptor;
 }
开发者ID:mkraemer,项目名称:react-inotify,代码行数:20,代码来源:Inotify.php

示例11: __construct

 /**
  * Constructor
  */
 public function __construct()
 {
     if (Daemon::loadModuleIfAbsent('inotify')) {
         $this->inotify = inotify_init();
         stream_set_blocking($this->inotify, 0);
     }
     Timer::add(function ($event) {
         Daemon::$process->fileWatcher->watch();
         if (sizeof(Daemon::$process->fileWatcher->files) > 0) {
             $event->timeout();
         }
     }, 1000000.0 * 1, 'fileWatcher');
 }
开发者ID:shamahan,项目名称:phpdaemon,代码行数:16,代码来源:FileWatcher.php

示例12: __construct

 public function __construct()
 {
     if (is_callable('inotify_init')) {
         $this->inotify = inotify_init();
         stream_set_blocking($this->inotify, 0);
     }
     Daemon_TimedEvent::add(function ($event) {
         Daemon::$process->fileWatcher->watch();
         if (sizeof(Daemon::$process->fileWatcher->files) > 0) {
             $event->timeout();
         }
     }, 1000000.0 * 1, 'fileWatcherTimedEvent');
 }
开发者ID:J3FF3,项目名称:phpdaemon,代码行数:13,代码来源:FileWatcher.php

示例13: __construct

 /**
  * Creates a new instance of Watcher.
  */
 public function __construct()
 {
     $this->modifiedTimes = [];
     $this->listeners = [];
     $this->paths = [];
     if (function_exists('inotify_init')) {
         $this->inotify = inotify_init();
         $read = [$this->inotify];
         $write = null;
         $except = null;
         if (stream_select($read, $write, $except, 0) !== false) {
             stream_set_blocking($this->inotify, 0);
         } else {
             $this->inotify = null;
         }
     }
 }
开发者ID:gsouf,项目名称:pho,代码行数:20,代码来源:Watcher.php

示例14: run

 /**
  * @return Result
  */
 public function run()
 {
     /** @noinspection PhpUndefinedFunctionInspection */
     $inotify = inotify_init();
     $watches = $this->createInotifyWatches($inotify);
     stream_set_blocking($inotify, 0);
     while (true) {
         /** @noinspection PhpUndefinedFunctionInspection */
         $events = inotify_read($inotify);
         if ($events) {
             if ($this->clear) {
                 passthru('bash -c clear');
             }
             $this->runTasksForInotifyEvents($events);
         }
         sleep(1);
     }
     $this->shutdownInotify($inotify, $watches);
     return $this->gasp->result()->setStatus(Result::SUCCESS)->setMessage('And now his watch is ended.');
 }
开发者ID:griffbrad,项目名称:gasp,代码行数:23,代码来源:Watch.php

示例15: __construct

 /**
  * @param $serverPid
  * @throws NotFound
  */
 function __construct($serverPid)
 {
     $this->pid = $serverPid;
     if (posix_kill($serverPid, 0) === false) {
         throw new NotFound("Process#{$serverPid} not found.");
     }
     $this->inotify = inotify_init();
     $this->events = IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE;
     swoole_event_add($this->inotify, function ($ifd) {
         $events = inotify_read($this->inotify);
         if (!$events) {
             return;
         }
         var_dump($events);
         foreach ($events as $ev) {
             if ($ev['mask'] == IN_IGNORED) {
                 continue;
             } else {
                 if ($ev['mask'] == IN_CREATE or $ev['mask'] == IN_DELETE or $ev['mask'] == IN_MODIFY or $ev['mask'] == IN_MOVED_TO or $ev['mask'] == IN_MOVED_FROM) {
                     $fileType = strstr($ev['name'], '.');
                     //非重启类型
                     if (!isset($this->reloadFileTypes[$fileType])) {
                         continue;
                     }
                 }
             }
             //正在reload,不再接受任何事件,冻结10秒
             if (!$this->reloading) {
                 $this->putLog("after 10 seconds reload the server");
                 //有事件发生了,进行重启
                 swoole_timer_after($this->afterNSeconds * 1000, array($this, 'reload'));
                 $this->reloading = true;
             }
         }
     });
 }
开发者ID:jonny77,项目名称:auto_reload,代码行数:40,代码来源:AutoReload.php


注:本文中的inotify_init函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。