phpstreamserver/file-monitor

File Monitor plugin for PHPStreamServer

v0.3.0 2024-12-06 17:26 UTC

This package is auto-updated.

Last update: 2024-12-06 17:57:00 UTC


README

File Monitor Plugin for PHPStreamServer

PHP >=8.2 Version Downloads

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