PHP code example of ahmard / swotch

1. Go to this page and download the library: Download ahmard/swotch 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/ */

    

ahmard / swotch example snippets


use Swotch\Watcher;

R__ . '/app/',
    __DIR__ . '/views/',
];

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

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

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