thesis / hot-reload
Thesis Hot Reload
Fund package maintenance!
0.3.0
2026-03-29 20:56 UTC
Requires
- php: ^8.4
- ext-pcntl: *
- ext-posix: *
- amphp/amp: ^3.0
- amphp/byte-stream: ^2.1
- revolt/event-loop: ^1.0
- symfony/console: ^8.0
- thesis/exceptionally: ^0.2.0
Requires (Dev)
- amphp/http-server: ^3.4
- amphp/log: ^2.0
- phpunit/phpunit: ^12.4
- symfony/var-dumper: ^7.4
README
Watches files for changes and automatically restarts a command.
Useful for development servers, workers, or any long-running PHP process.
Supports debouncing to avoid redundant restarts when multiple files change at once.
Installation
composer require thesis/hot-reload --dev
Requires PHP 8.4+.
Usage
vendor/bin/hot-reload [options] [--] <cmd>
Options
| Option | Description | Default |
|---|---|---|
--path |
Paths to watch (repeatable) | [src] |
--ext |
File extensions to watch (repeatable; if none, all are watched) | [] |
--exclude |
Patterns to exclude (repeatable, e.g. *.generated.php) |
[] |
--debounce |
Delay in seconds before restarting after a change | 0.1 |
Examples
# Watch src/, restart on any file change vendor/bin/hot-reload -- php server.php # Watch multiple paths, only .php files vendor/bin/hot-reload --path=src --path=config --ext=php -- php server.php # Exclude generated files vendor/bin/hot-reload --path=src --ext=php --exclude='*.generated.php' -- php server.php # Increase debounce delay (useful when many files change at once) vendor/bin/hot-reload --debounce=0.5 -- php server.php
PHP API
You can use the watcher directly in PHP instead of the CLI binary:
use Thesis\HotReload\Process\Tty; use Thesis\HotReload\Target; use Thesis\HotReload\Watcher; $exitCode = new Watcher()->watch( target: new Target( paths: ['src'], extensions: ['php'], excludes: ['*.generated.php'], ), start: static fn() => Tty::start(['php', 'server.php']), debounce: 0.1, ); exit($exitCode);
Tty::start() accepts either a string command or an array of arguments (which will be shell-escaped).
To use a custom process, implement the Thesis\HotReload\Process interface.
Roadmap
-
inotify-based change detector for Linux (event-driven, no polling)
License
MIT