Skip to main content

File Monitor Plugin

The File Monitor Plugin is designed to monitor specified directories for file changes. It automatically reloads workers whenever a file within those directories is modified.

Installationā€‹

$ composer require phpstreamserver/file-monitor

Example of usageā€‹

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: 'Worker process',
onStart: function (WorkerProcess $worker): void {
$worker->logger->notice("Worker process has started");
},
),
);

exit($server->run());

Configurationā€‹

šŸ”Œ FileMonitorPluginā€‹

OptionTypeDefaultDescription
watch...WatchDirnotĀ setList of WatchDir objects that define the files to monitor for changes.

šŸ”µ WatchDirā€‹

OptionTypeDefaultDescription
sourceDirstringnotĀ setThe directory to monitor for file changes.
filePatternstring[]['*']Optional. A pattern that specifies which files to watch (e.g., *.php).
invalidateOpcacheboolfalseOptional. Whether to invalidate the OPCache when a file change is detected.