robert-grubb / php-hotreload
Hot reload for scripts that stay alive via CLI.
Installs: 34
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/robert-grubb/php-hotreload
Requires
- php: >=8.0.0
 - codedungeon/php-cli-colors: ^1.12
 
README
This is a simple package that will allow you to live reload a script that would stay alive via a cli command (daemon). For example, if you have a infinite while loop running in a script and do not want to stop and restart every time you make a change, this package will work well for you.
Credit
Thanks to the package felippe-regazio/php-hot-reloader for a great way to check for changes with a directory and files.
Installing
composer require robert-grubb/php-hotreload
Usage
require_once __DIR__ . '/vendor/autoload.php';
/**
 * Instantiates new HotReloader and listens for changes the directory
 * specified except for the ignored directory.
 */
$hotReloader = new HotReload\Instance([
    'entryFile' => __DIR__ . '/test.php', // Entry file to run command
    'entryArguments' => false, // String of arguments for entry (ex. --foo=bar)
    'rootDirectory' => __DIR__, // The root directory
    'watch' => [ '.' ], // List of files/directories to watch (Relative path to root)
    'ignore' => [ 'ignored' ] // List of files/directories to ignore (Relative path to root)
]);
/**
 * Start the reload watcher
 */
$hotReloader->startWatcher();
