- What is cartalyst/resource-watcher used for in Laravel?
- It is a PHP library that watches files and directories and dispatches events when resources are created, modified, or deleted. In Laravel apps it is typically used for developer tooling or internal automation such as cache invalidation, asset recompilation triggers, config or template drift detection, or log monitoring. It is not a customer-facing request-path dependency; treat it as an implementation detail behind your own small service contract.
- How do I install cartalyst/resource-watcher with Composer?
- Run composer require cartalyst/resource-watcher in your project. The package advertises an optional Laravel service provider and facade, so you can use it standalone in plain PHP or wire it into Laravel's container. Verify the composer.json constraints against your PHP and Laravel versions before adopting, because older Cartalyst packages may not cover PHP 8.x or Laravel 10/11.
- Does cartalyst/resource-watcher support Laravel 10 and Laravel 11?
- The package advertises optional Laravel integration via a service provider and facade, but the context does not confirm Laravel 10 or Laravel 11 compatibility. Check the composer.json constraints and run a quick install and test spike on your target runtime. If constraints block PHP 8.x or Laravel 10/11, keep it out of the main app or wrap and replace it.
- Does Resource Watcher use inotify or polling?
- The package description advertises configurable polling intervals between checks, but source-level evidence is contradictory and may point to the Linux inotify extension. Resolve this from the package source rather than the README before committing, because the mechanism determines macOS and Windows support, Docker Desktop bind-mount behavior, and container suitability. If polling is available as a fallback, it works everywhere but CPU cost scales with watch breadth and interval.
- Can I watch only certain file extensions or directories?
- Yes. The package supports watching individual files or directory trees and filtering watched resources by extension, name, or pattern. Use filters to avoid recursively watching vendor or node_modules, which degrades both polling and inotify-based designs. Keep watch scope as narrow as possible in production.
- How do I handle duplicate events from editor atomic saves?
- Editors often save atomically by writing a temp file and renaming it, which can surface as delete plus create rather than a single modify event. Without debouncing and event coalescing, your handlers may fire several times per save, and compilers touching directory trees can trigger event storms. Add a debounce and coalesce layer in your adapter and test with your team's actual editors.
- What are the production risks of using Resource Watcher?
- If inotify-backed, you can hit inotify watch exhaustion and misleading ENOSPC errors; if polling, you get silent latency drift and load on busy filesystems. Recursive watching of large directories such as vendor or node_modules degrades either design. Avoid putting it in customer request paths and scope it to console commands, workers, or internal tooling.
- Is cartalyst/resource-watcher maintained and safe to depend on?
- The project has very low visible ecosystem traction, around 7 stars and 0 dependents, and no clear maintainer cadence, so there is little downstream ecosystem to absorb fixes or inherited security patching. The BSD-2-Clause license and tiny API surface make legal friction and exit cost low, but adopting means owning it. Assign an internal owner before merge and isolate it behind your own interface.
- What alternatives should I consider to cartalyst/resource-watcher?
- Evaluate spatie/file-system-watcher, which is fswatch-based, yosymfony/resource-watcher, which is polling-based, or delegating watching to Vite or Node tooling depending on your exact use case. Choose based on mechanism, platform support, and whether you need a Laravel service provider or just a standalone PHP watcher. If the feature is only a watch-and-rebuild loop, your frontend build tool may already solve it.
- How should I test a Laravel app that uses Resource Watcher?
- Wrap the package behind your own small contract such as watch, on, and start, then fake or stub that contract in tests so no controller, job, or domain service imports the package namespace directly. Use integration tests with temporary directories for create, modify, and delete behavior, including atomic-save patterns. Keep the watcher out of request-path tests and verify platform behavior in the same container or runtime you deploy.