Skip to content

Ahmard/swotch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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