phpstreamserver / file-monitor
File Monitor plugin for PHPStreamServer
v0.3.0
2024-12-06 17:26 UTC
Requires
- php: >=8.2
- ext-pcntl: *
- ext-posix: *
- amphp/amp: ^3.0.2
- luzrain/polyfill-inotify: ^1.0
- phpstreamserver/core: ^0.3
- revolt/event-loop: ^1.0.6
README
File Monitor Plugin for PHPStreamServer
The File Monitor Plugin for PHPStreamServer extends the core functionality by automatically monitoring file changes within specified directories.
When changes are detected, the plugin triggers a workers reload. In always-in-memory architectures, the server must to be reloaded to take effect after file changes.
Useful for development environments.
Features
- Watch specific files in specific directories.
- Uses inotify signals from the operating system.
Install
$ composer require phpstreamserver/core phpstreamserver/file-monitor
Configure
Here is an example of a simple server configuration.
Each time the files in the directory change, the server is reloaded.
// server.php use PHPStreamServer\Core\Plugin\Supervisor\WorkerProcess; use PHPStreamServer\Core\Server; use PHPStreamServer\Plugin\FileMonitor\FileMonitorPlugin; use PHPStreamServer\Plugin\FileMonitor\WatchDir; $server = new Server(); $server->addPlugin( new FileMonitorPlugin( new WatchDir(sourceDir: __DIR__, filePattern: ['*'], invalidateOpcache: true) ), ); $server->addWorker( new WorkerProcess( name: 'Supervised Program', count: 1, onStart: function (WorkerProcess $worker): void { // custom long running process }, ), ); exit($server->run());
Run
$ php server.php start