PHP code example of slick / fswatch

1. Go to this page and download the library: Download slick/fswatch library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

slick / fswatch example snippets


use Slick\FsWatch\Directory;

$dir = new Directory('/path/to/directory');
// can be stored in any cache or temporary memory to be checked later
$snapshot = $dir->snapshot();
file_put_contents('/some/cache/file', serialize($snapshot)); 


use Slick\FsWatch\Directory;

$dir = new Directory('/path/to/directory');
$snapshot = unserialize(file_get_contents('/some/cache/file'))

if ($dir->hasChanged($snapshot)) { //directory contents have changed
    $changes = $dir->snapshot()->compareTo($snapshot);
    // do your logic
}

use Slick\FsWatch\Directory;
use Slick\FsWatch\Watcher;

$dir = new Directory('/path/to/directory');

$watcher = new Watcher($dir, function (Directory $dir) => {
    // do your logic on file change
});

// This will run until Ctrl + C (SIGINT) is pressed.
// You can pass an expression of callable to determine the end of the execution
$watcher->watch(Watcher::SIGINT);