Giter Site home page Giter Site logo

fsnotify's Introduction

FsNotify

Build Status License

Event based file system watcher for PHP. FsNotify is fully† async and event based using Amp and Symfony\EventDispatcher.

† excluding stat operations to determine file metadata

Usage

Quick start

<?php

use Denimsoft\FsNotify\Event\FileEvent;
use Denimsoft\FsNotify\FsNotifyBuilder;

require_once __DIR__ . '/vendor/autoload.php';

$fsNotify = (new FsNotifyBuilder())
    ->addWatcher(__DIR__ . '/src', true)
    ->getBuilder()
    ->addChangeListener(function (FileEvent $event) {
        echo sprintf(
                "[%s] (%s) \"%s\" %s\n",
                date('c'),
                $event->getEventName(),
                $event->getFilepath(),
                json_encode($event->getMetadata())
            );
    })
    ->createFsNotify();

$fsNotify->start();

Advanced usage

FsNotify supports monitoring multiple paths with configurable callbacks and filters. See the examples directory for complete usage:

This library was developed with the laravel-ide-helper use case in mind, it highlights a moderately complicated yet useful usage scenario.

Adapters

PhpAdapter - fallback adapter if no other adapters are supported. PhpAdapter uses file polling to detect changes. The adapter defaults to a configurable polling interval of 1 second. It is sufficient for monitoring a small amount of files.

FswatchAdapter - fswatch requires the GNU CLI tool fswatch, it's more performant than PhpAdapter and detects file changes almost instantaneously. It is preferred in most cases but can be slow to propagate large amounts of file deletions (such as deleting the vendor or node_modules folder of a PHP or JavaScript project respectively); however, this use case is considered atypical and should not affect most users. It also does not initially recurse into a copied or moved directory but this is once again not typically a requirement when watching for changes to Laravel models or static asset directories before executing a third-party tool.

fsnotify's People

Contributors

andrewmackrodt avatar

Stargazers

 avatar

Watchers

 avatar

fsnotify's Issues

Packagist package

Hi,

can you upload this to packagist.org so that we can do just composer require andrewmackrodt/fsnotify?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.