PHP Classes

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

Recommend this page to a friend!
  Info   View files Documentation   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2023-09-18 (3 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 41 All time: 10,758 This week: 118Up
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: 23 packages by
Country: Nigeria Nigeria
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  
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  /  src  
File Role Description
  Plain text file AbstractEvent.php Class Class source
  Plain text file Watcher.php Class Class source

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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:41
This week:0
All time:10,758
This week:118Up