/**
* Long pooling sync checker
* This function require server command `inotifywait`
* If `inotifywait` need full path, Please add `define('ELFINER_INOTIFYWAIT_PATH', '/PATH_TO/inotifywait');` into connector.php
*
* @param string $path
* @param int $standby
* @param number $compare
* @return number|bool
*/
public function localFileSystemInotify($path, $standby, $compare)
{
if (isset($this->sessionCache['localFileSystemInotify_disable'])) {
return false;
}
$path = realpath($path);
$mtime = filemtime($path);
if ($mtime != $compare) {
return $mtime;
}
$inotifywait = defined('ELFINER_INOTIFYWAIT_PATH') ? ELFINER_INOTIFYWAIT_PATH : 'inotifywait';
$path = escapeshellarg($path);
$standby = max(1, intval($standby));
$cmd = $inotifywait . ' ' . $path . ' -t ' . $standby . ' -e moved_to,moved_from,move,close_write,delete,delete_self';
$this->procExec($cmd, $o, $r);
if ($r === 0) {
// changed
clearstatcache();
$mtime = @filemtime($path);
// error on busy?
return $mtime ? $mtime : time();
} else {
if ($r === 2) {
// not changed (timeout)
return $compare;
}
}
// error
// cache to $_SESSION
$sessionStart = $this->sessionRestart();
if ($sessionStart) {
$this->sessionCache['localFileSystemInotify_disable'] = true;
elFinder::sessionWrite();
}
return false;
}