symfony/web-profiler-bundle
Provides the Symfony Web Profiler and debug toolbar for development. Inspect requests, routing, templates, database queries, logs, events, and performance metrics via an in-browser UI to speed up debugging and optimization.
symfony/web-profiler-bundle is a first-class citizen in the Symfony ecosystem, designed to integrate seamlessly with Symfony’s HTTP kernel, dependency injection, and event system. For Laravel projects leveraging Symfony components (e.g., via symfony/http-foundation, symfony/routing, or symfony/debug-bundle), this package can be adapted with minimal friction.dd() or dump() methods, offering structured, request-scoped insights without polluting logs or requiring external tools (e.g., Blackfire, Xdebug).symfony/http-kernel to wrap Laravel’s Request/Response objects and inject them into the ProfilerBundle.APP_DEBUG=true).Profiler and DataCollector interfaces as Laravel services, mapping them to Symfony’s implementations.UrlGenerator. Workaround: Use Symfony’s Router alongside Laravel’s or mock URLs for profiler links.laravelcollective/html), the Twig panel will work; otherwise, custom collectors are needed.staging/production).| Risk Area | Mitigation Strategy |
|---|---|
| Symfony Dependency | Abstract Symfony-specific code behind interfaces (e.g., ProfilerInterface) to allow swapping implementations. |
| Routing Conflicts | Exclude profiler routes (/_profiler/, /_wdt/) from Laravel’s router or use a subdomain (e.g., app.dev._profiler). |
| Middleware Collisions | Ensure profiler middleware runs last (after auth, CORS, etc.) to avoid blocking toolbar access. |
| Custom Collector Gaps | Build a Laravel-specific collector (e.g., for Eloquent queries, Blade templates) to fill gaps left by Symfony’s assumptions. |
| Cache Invalidation | Clear Laravel’s cache (php artisan cache:clear) and Symfony’s cache (php bin/console cache:clear) when adding collectors. |
| Security Risks | Never enable in production. Use Laravel’s APP_ENV checks to gate profiling. |
Symfony Adoption:
HttpKernel for profiling while keeping Laravel’s routing)?Debugging Workflows:
Performance Tradeoffs:
Long-Term Maintenance:
Alternatives:
laravel-debugbar (simpler, but less feature-rich)?spatie/laravel-query-logger (for SQL-specific profiling)?barryvdh/laravel-debugbar (Debugbar integration)?symfony/http-foundation, symfony/routing, symfony/debug).DataCollector interface).| Step | Action | Tools/Commands | Notes |
|---|---|---|---|
| 1 | Assess Symfony Usage | Review composer.json for Symfony packages. |
Identify dependencies that can leverage the profiler (e.g., symfony/routing). |
| 2 | Install Dependencies | composer require symfony/web-profiler-bundle symfony/http-kernel symfony/framework-bundle |
Install core Symfony components needed for the profiler. |
| 3 | Set Up Symfony Kernel | Create a SymfonyKernel class extending Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait. |
Wrap Laravel’s Request/Response in Symfony equivalents. |
| 4 | Configure Environment | Add to .env: APP_DEBUG=true, APP_ENV=dev. |
Enable profiling only in development. |
| 5 | Register Middleware | Add middleware to bootstrap Symfony’s profiler. | Example: ProfilerMiddleware::class that initializes Profiler::enable(). |
| 6 | Route Profiler Endpoints | Exclude /_profiler/* from Laravel’s router or proxy to Symfony. |
Use a subdomain or path prefix (e.g., /debug/_profiler). |
| 7 | Build Custom Collectors | Extend Symfony\Component\HttpKernel\DataCollector\DataCollector for Laravel-specific data (e.g., Eloquent queries). |
Example: LaravelQueryCollector for DB::query() logging. |
| 8 | Test Integration | Run php artisan serve and visit /_profiler/. |
Verify toolbar and panels appear. |
| 9 | Optimize Performance | Disable profiling in CI/CD or use --env=test. |
Add APP_DEBUG=false to .env.testing. |
| Component | Compatibility Notes |
|---|---|
| Laravel Request/Response | Must be wrapped in Symfony’s Request/Response for full profiler support. |
| Routing | Symfony’s Router conflicts with Laravel’s. Use Symfony’s router for profiler links or mock URLs. |
| Twig | Works if using laravelcollective/html or similar. Otherwise, custom collectors needed. |
| Doctrine | Only works if using Symfony’s DoctrineBundle. For Eloquent, build a custom collector. |
| Middleware | Profiler middleware must run after auth/CORS to avoid blocking toolbar access. |
| Cache | Clear both Laravel (php artisan cache:clear) and Symfony (php bin/console cache:clear) caches. |
| Events | Symfony’s EventDispatcher must be bridged to Laravel’s Events facade for full event panel support. |
Phase 1: Core Integration (2-3 days)
Phase 2: Custom Collectors (3-5 days)
LaravelQueryCollector to log all DB:: queries.How can I help you explore Laravel packages today?