PHP code example of myvon / reactphp-file-system-watcher

1. Go to this page and download the library: Download myvon/reactphp-file-system-watcher 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/ */

    

myvon / reactphp-file-system-watcher example snippets


use Myvon\Watcher\Watch;

Watch::path($directory)
    ->onFileCreated(function (string $newFilePath) {
        // do something...
    })
    ->start();

use Myvon\Watcher\Watch;

$watcher = Watch::path($directory)
    ->onAnyChange(function (string $type, string $path) {
        if ($type === Watch::EVENT_TYPE_FILE_CREATED) {
            echo "file {$path} was created";
        }
    })
    ->start();

use Myvon\Watcher\Watch;

Watch::path($directory)
    ->onFileCreated(function (string $newFilePath) {
        // do something...
    });

use Myvon\Watcher\Watch;

Watch::paths($directory, $anotherDirectory);

use Myvon\Watcher\Watch;

Watch::path($directory)
    ->onFileCreated(function (string $newFilePath) {
        // do something on file creation...
    })
    ->onFileCreated(function (string $newFilePath) {
        // do something else on file creation...
    })
    ->onAnyChange(function (string $type, string $path) {
        // do something...
    })
    ->onAnyChange(function (string $type, string $path) {
        // do something else...
    })
    // ...

use Myvon\Watcher\Watch;

Watch::path($directory)
    ->shouldContinue(function () {
        // return true or false
    })
    // ...

use Myvon\Watcher\Watch;

$watcher = Watch::path($directory);
// ...
$watcher->stop();

use Myvon\Watcher\Watch;

Watch::path($directory)
    ->setIntervalTime(0.1) //unit is seconds therefore -> 0.1s
    // ...rest of your methods

use Myvon\Watcher\Watch;

Watch::path($directory)
    ->start(null, 0.1); //unit is seconds therefore -> 0.1s
    // ...rest of your methods

use Myvon\Watcher\Watch;

$loop = new MyCustomLoop();

Watch::path($directory)
    ->start($loop);