ralfhortt/php-watch-files

Watch file or folder and execute code when something is changes inside

1.0.0 2022-04-16 10:02 UTC

This package is auto-updated.

Last update: 2024-11-16 15:42:28 UTC


README

Watch file or folder and execute code when something is changed inside

Demo

You can run the following command to see how the script works

php index.php FILE_OR_FOLDER_PATH

Basic usage

$watcher = new \ralfhortt\fswatcher\Watcher('FILE_OR_FOLDER_PATH_TO_WATCH', function ($event) {
    // Do whatever you want when file or folder is changed.
    if ($event->isAddition()){
        // File was added and file path will be $event->file
    } else if ($event->isModification()){
        // File was modified and file path will be $event->file
    }
});
$watcher->watch();

Advanced Usage

$watcher = new \ralfhortt\fswatcher\Watcher('FILE_OR_FOLDER_PATH_TO_WATCH', 'callback', [
    'watchInterval' => 5,
    'cacheChanges' => true
]);

Options

Credits