- What Laravel versions does this package support?
- This package requires PHP 8.2+ and is designed for Laravel 9/10. While it may work with older Laravel versions, test thoroughly for compatibility with attributes, enums, or modern PHP features used in your implementation.
- How do I integrate this with an existing profiler like Blackfire or XHProf?
- Implement the `AdapterInterface` to bridge your profiler’s data with the contracts. For example, wrap Blackfire’s output in a class adhering to `ProfilerInterface` and register it in Laravel’s service container via `AppServiceProvider`.
- Can I use this for async profiling (e.g., Laravel queues)?
- The contracts don’t natively support async profiling, but you can extend `ProfilerInterface` to include event-driven methods. Use Laravel’s `dispatch()` or queue listeners to trigger profiling after job completion.
- What’s the minimal setup to start profiling in Laravel?
- Bind the `ProfilerInterface` to a custom implementation in `AppServiceProvider`, then wrap critical code with `start()`/`snapshot()`/`store()` calls. Example: `$profiler->start('route.handler'); // ... $profiler->snapshot()->store();`
- How do I store profiling snapshots (e.g., database, cache)?
- Implement `SaverInterface` to define storage logic. For databases, use Eloquent models; for cache, leverage Laravel’s `Cache` facade. Register your saver in the container to handle snapshot persistence.
- Will this impact production performance if always enabled?
- Yes, profiling adds overhead. Use environment-based toggles (e.g., `config('profiling.enabled')`) or middleware to disable it in production. Consider sampling snapshots for high-traffic apps.
- Are there built-in filters for profiling data?
- Yes, implement `FilterInterface` to customize snapshot data before storage. For example, exclude internal routes or sanitize sensitive query parameters. Combine multiple filters via dependency injection.
- How do I test this package in PHPUnit?
- Mock the `ProfilerInterface` and `SaverInterface` in tests. Verify snapshot data with assertions like `assertEquals(100, $snapshot->getDurationMs())`. Use Laravel’s `Mockery` or PHPUnit’s built-in mocking.
- What alternatives exist for Laravel profiling?
- Consider Laravel Telescope (built-in), Blackfire (commercial), or Xdebug (debugging). This package differs by providing *contracts*—ideal if you need custom implementations or want to avoid vendor lock-in.
- How do I handle profiling failures (e.g., storage errors)?
- Implement `ExceptionInterface` in your saver/profiler to catch failures. Log errors via Laravel’s `Log` facade or notify via `notify()` with a custom `Notification`. Default to silent degradation or alerts.