本文整理汇总了PHP中inotify_init函数的典型用法代码示例。如果您正苦于以下问题:PHP inotify_init函数的具体用法?PHP inotify_init怎么用?PHP inotify_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了inotify_init函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: tail
/**
* 监控日志文件
*
* @param array $logPaths
* @return void
* @throws ZtChart_Model_Monitor_Exception
*/
public function tail($logPaths)
{
if (($inotify = inotify_init()) === false) {
throw new ZtChart_Model_Monitor_Daemon_Exception('Failed to obtain an inotify instance.');
}
$watchFiles = $watchDirs = array();
foreach ($logPaths as $file) {
if (($watch = inotify_add_watch($inotify, $file, IN_CREATE | IN_MODIFY)) === false) {
throw new ZtChart_Model_Monitor_Daemon_Exception("Failed to watch file '{$file}'.");
}
if (is_file($file)) {
if (false === ($fd = fopen($file, "r"))) {
throw new ZtChart_Model_Monitor_Daemon_Exception("File '{$file}' is not readable.");
}
$this->_ffseek($fd);
$watchFiles[$watch] = $fd;
} else {
if (is_dir($file)) {
$watchFiles[$watch] = array();
$watchDirs[$watch] = $file;
}
}
}
while (($events = inotify_read($inotify)) !== false) {
foreach ($events as $event) {
if ($event['mask'] & IN_Q_OVERFLOW) {
throw new ZtChart_Model_Monitor_Daemon_Exception("The number of inotify queued events reaches upper limit.");
}
if (!$this->accept($event['name'])) {
continue;
}
if ($event['mask'] & (IN_CREATE | IN_MODIFY)) {
if (!($event['mask'] & IN_ISDIR)) {
if (!array_key_exists($event['name'], $watchFiles[$event['wd']])) {
$fn = $fd = null;
foreach ($watchFiles[$event['wd']] as $wfn => $wfd) {
if (strncasecmp($wfn, $event['name'], strpos($wfn, '.')) == 0) {
$fn = $wfn;
$fd = $wfd;
break;
}
}
// 判断当前创建或修改的日志文件是否最新
if (strcasecmp($fn, $event['name']) < 0) {
if (is_resource($fd) && fclose($fd)) {
unset($watchFiles[$event['wd']][$fn]);
}
$filename = $watchDirs[$event['wd']] . DIRECTORY_SEPARATOR . $event['name'];
if (false === ($fd = fopen($filename, "r"))) {
$this->_logger->err("File '{$filename}' is not readable\n");
continue;
}
if ($event['mask'] & IN_MODIFY) {
$this->_ffseek($fd);
}
$watchFiles[$event['wd']][$event['name']] = $fd;
} else {
// 如果不是最新的日志文件(重写的上一个小时的日志文件),则不处理。
continue;
}
} else {
$fd = $watchFiles[$event['wd']][$event['name']];
}
} else {
continue;
// $fd = $watchFiles[$event['wd']];
}
// 读取日志并分析
$raw = '';
$lines = 0;
while (true) {
$raw .= $block = fread($fd, 4096);
if (false !== ($pos = strpos($raw, "\n"))) {
$rawline = substr($raw, 0, $pos + 1);
try {
$mlog = new ZtChart_Model_Monitor_Log($rawline);
$line = $mlog->transform();
if (!empty($line)) {
$this->_shmWrite($mlog->getShmIdentifier(), $line);
$lines++;
}
} catch (ZtChart_Model_Monitor_Log_Exception $e) {
$this->_logger->warn("日志处理错误:" . iconv('GBK', 'UTF-8', $rawline));
}
$raw = substr($raw, $pos + 1);
} else {
if (($offset = strlen($block)) > 0) {
fseek($fd, -$offset, SEEK_CUR);
}
break;
}
}
if (0 != $lines) {
//.........这里部分代码省略.........
开发者ID:starflash,项目名称:ZtChart-ZF1-Example,代码行数:101,代码来源:Realtime.php
示例17: __construct
/**
* Constructor
*/
public function __construct()
{
$this->inotifyStreamDescriptor = inotify_init();
stream_set_blocking($this->inotifyStreamDescriptor, 0);
register_tick_function([$this, 'tick']);
}
开发者ID:thinframe,项目名称:inotify,代码行数:9,代码来源:FileSystemWatcher.php
示例18: __construct
/**
* Watcher constructor.
*/
public function __construct()
{
$this->inotify = inotify_init();
}
开发者ID:JanHuang,项目名称:swoole,代码行数:7,代码来源:Watcher.php
示例19: array
<?php
class G
{
static $users = array();
static $files = array();
static $watchList = array();
static $inotify;
}
$server = new swoole_websocket_server("0.0.0.0", 9502, SWOOLE_BASE);
$server->on('WorkerStart', function (swoole_websocket_server $server, $worker_id) {
G::$inotify = inotify_init();
swoole_event_add(G::$inotify, function ($ifd) use($server) {
$events = inotify_read(G::$inotify);
if (!$events) {
return;
}
foreach ($events as $event) {
$filename = G::$watchList[$event['wd']];
$line = fgets(G::$files[$filename]['fp']);
if (!$line) {
echo "fgets failed\n";
}
//遍历监听此文件的所有用户,进行广播
foreach (G::$files[$filename]['users'] as $fd) {
$server->push($fd, $line);
}
}
});
});
$server->on('Message', function (swoole_websocket_server $server, $frame) {
开发者ID:matyhtf,项目名称:websocket_tail,代码行数:31,代码来源:server.php
示例20: start
public function start()
{
$paths = $this->_paths;
if ($this->_followLinks) {
$paths = LinksHelper::followLinks($paths, $this->_excludePatterns);
}
$this->_fd = inotify_init();
$finder = new Finder();
$finder->directories();
foreach ($this->_excludePatterns as $excludePattern) {
$finder->notName($excludePattern);
}
foreach ($paths as $p) {
$finder->in($p);
}
$this->_watches = array();
foreach ($paths as $p) {
$this->_addWatch($p);
}
foreach ($finder as $f) {
$this->_addWatch($f->__toString());
}
$this->_logger->info("Watches set up...");
$read = array($this->_fd);
$write = null;
$except = null;
stream_select($read, $write, $except, 0);
stream_set_blocking($this->_fd, 0);
$events = array();
while (!$this->_stopped) {
while ($inotifyEvents = inotify_read($this->_fd)) {
foreach ($inotifyEvents as $details) {
$file = $this->_watches[$details['wd']];
if ($details['name']) {
$file .= '/' . $details['name'];
}
if ($details['mask'] & IN_MODIFY || $details['mask'] & IN_ATTRIB) {
$events[] = new ModifyEvent($file);
}
if ($details['mask'] & IN_CREATE) {
$events[] = new CreateEvent($file);
}
if ($details['mask'] & IN_DELETE) {
$events[] = new DeleteEvent($file);
}
if ($details['mask'] & IN_MOVED_FROM) {
$this->_previousMoveFromFile = $file;
}
if ($details['mask'] & IN_MOVED_TO) {
if (!isset($this->_previousMoveFromFile)) {
$this->_logger->error('MOVED_FROM event is not followed by a MOVED_TO');
} else {
$events[] = new MoveEvent($this->_previousMoveFromFile, $file);
unset($this->_previousMoveFromFile);
}
}
if ($details['mask'] & IN_DELETE_SELF) {
unset($this->_watches[$details['wd']]);
}
}
}
$events = $this->_compressEvents($events);
if ($this->_queueSizeLimit && count($events) > $this->_queueSizeLimit) {
$this->_dispatchEvent(QueueFullEvent::NAME, new QueueFullEvent($events));
$events = array();
}
foreach ($events as $event) {
$name = call_user_func(array(get_class($event), 'getEventName'));
$this->_dispatchEvent($name, $event);
}
usleep(100 * 1000);
}
foreach ($this->_watches as $wd => $path) {
inotify_rm_watch($this->_fd, (int) $wd);
}
fclose($this->_fd);
return;
}
开发者ID:koala-framework,项目名称:file-watcher,代码行数:78,代码来源:Inotify.php
注:本文中的inotify_init函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论