https://github.com/phpstreamserver/file-monitor
[READ ONLY] File Monitor Plugin for PHPStreamServer
https://github.com/phpstreamserver/file-monitor
phpstreamserver
Last synced: 12 months ago
JSON representation
[READ ONLY] File Monitor Plugin for PHPStreamServer
- Host: GitHub
- URL: https://github.com/phpstreamserver/file-monitor
- Owner: phpstreamserver
- Created: 2024-11-22T17:39:32.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-06T13:53:19.000Z (over 1 year ago)
- Last Synced: 2025-04-08T08:46:26.645Z (about 1 year ago)
- Topics: phpstreamserver
- Language: PHP
- Homepage: https://phpstreamserver.dev
- Size: 14.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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
```bash
$ 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.
```php
// server.php
use PHPStreamServer\Core\Server;
use PHPStreamServer\Core\Worker\WorkerProcess;
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
```bash
$ php server.php start
```