PHP code example of ralfhortt / php-watch-files

1. Go to this page and download the library: Download ralfhortt/php-watch-files 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/ */

    

ralfhortt / php-watch-files example snippets


$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();

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