PHP code example of crodas / watch-files
1. Go to this page and download the library: Download crodas/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/ */
crodas / watch-files example snippets
use WatchFiles\Watch;
// we'd like to watch some files
// and to save its state in foobar.php
$foobar = new Watch("foobar.php");
if ($foobar->isWatching()) {
if (!$foobar->hasChanged()) {
// somebody else before us started watching files/dirs
// on foobar.php and *nothing* changed since last
// time
return;
}
// do heavy stuff here (Recompile it?)
// we need to tell the watch that we're aware of lastest
// changes and we'd like to update the file modification time
$foobar->rebuild();
return;
}
// we'd love to see when a new file has been added or deleted
$foobar->watchDir("foodir");
$foobar->watchDirs(array("foodir", 'foobar'));
// or monitor changes inside file or files
$foobar->watchFile("foodir.php");
$foobar->watchFiles(array("foodir.php", 'foobar.php'));
// start watching!
$foobar->watch();