PHP Classes

Swotch PHP File Change Event Watch: Watch file changes in PHP Swoole applications

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 44 All time: 10,814 This week: 488Up
Version License PHP version Categories
swotch 1.0.0Shareware8System information, Files and Folders, P...
Description 

Author

This package can watch file changes in PHP Swoole applications.

It can register a list of paths of directories to watch for file changes.

The package can also register callback functions that will be called when several types of events on files in the registered directories happen.

Currently, the package can invoke callback functions when changes happen in the registered directories like:

- A file was modified

- A file was moved

- A file was deleted

- A file was created

Innovation Award
PHP Programming Innovation award nominee
September 2023
Number 6
Swoole is a PHP asynchronous programming framework that allows developers to create high-performance PHP applications by highly optimizing the server CPUs in the server computer on which PHP applications are running.

It uses asynchronous programming to let developers define multiple PHP code sections that can run in parallel while other PHP code sections are waiting for tasks that access external resources that are not completed, like, for instance, database accesses, network connections, or file accesses.

This package implements a directory file watcher class that uses Swoole asynchronous support to process file changes in parallel with other tasks that your PHP Swoole-based applications may be performing.

Manuel Lemos
Picture of Ahmad Mustapha
Name: Ahmad Mustapha <contact>
Classes: 24 packages by
Country: Nigeria Nigeria
Age: ???
All time rank: 226511 in Nigeria Nigeria
Week rank: 178 Up7 in Nigeria Nigeria Up
Innovation award
Innovation award
Nominee: 9x

Documentation

Swotch

Swoole file system changes watcher.

Installation

composer require ahmard/swotch

Usage

Basic Usage

use Swotch\Watcher;

require 'vendor/autoload.php';

$paths = [
    __DIR__ . '/app/',
    __DIR__ . '/views/',
];

Watcher::watch($paths)->onAny(function (){
    echo "File changes detected\n";
});

Swoole Server Integration

use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Http\Server;
use Swotch\Watcher;

require 'vendor/autoload.php';

$server = new Server('0.0.0.0', 9000);
$server->on('request', function (Request $request, Response $response) {
    $response->end('Hello world');
});

$server->on('start', function (Server $server) {
    echo "Server started at http://0.0.0.0:9000\n";
    
    $paths = [
        __DIR__ . '/app/',
        __DIR__ . '/views/',
    ];
    
    Watcher::watch($paths)->onAny(fn() => $server->reload());
});

$server->start();

  Files folder image Files (8)  
File Role Description
Files folder imagesrc (2 files)
Files folder imagetests (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (8)  /  src  
File Role Description
  Plain text file AbstractEvent.php Class Class source
  Plain text file Watcher.php Class Class source

  Files folder image Files (8)  /  tests  
File Role Description
  Plain text file WatcherTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:44
This week:0
All time:10,814
This week:488Up