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.
Installation:
composer require symfony/web-profiler-bundle
For Laravel (Symfony 5+ compatible), add to config/app.php under extra.bundles (if using Symfony components):
'bundles' => [
// ...
Symfony\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
],
Enable Debug Mode:
Set APP_DEBUG=true in .env:
APP_DEBUG=true
APP_ENV=local
First Use Case:
php artisan serve + visit /).symfony/http-kernel./_profiler/ (e.g., http://localhost:8000/_profiler/).Debugging HTTP Requests:
500) to isolate errors.POST /api/login by inspecting headers, body, and response.Performance Profiling:
State Inspection:
404 by checking the Router panel for missing routes.Custom Data Collection (Laravel Integration):
// app/Collectors/CustomCollector.php
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Illuminate\Support\Facades\Cache;
class CustomCollector extends DataCollector {
public function collect($request, $response) {
$this->data['cache_hits'] = Cache::stats()['hits'] ?? 0;
return $this->data;
}
public function getName() { return 'laravel_cache'; }
}
config/profiler.php (if using Symfony’s profiler):
'collectors' => [
'laravel_cache' => App\Collectors\CustomCollector::class,
],
Integration with Laravel Debugbar:
barryvdh/laravel-debugbar) for Laravel-native profiling, then extend with Symfony’s profiler for advanced features (e.g., Doctrine, Twig).Toolbar Not Showing in Laravel:
HttpKernel (advanced).barryvdh/laravel-debugbar) as a drop-in alternative.symfony/web-server-bundle).Performance Overhead:
APP_DEBUG=false) and CI environments.--env=testing to avoid profiler noise.Doctrine Queries Missing:
doctrine/dbal or doctrine/orm is installed and configured.config/database.php:
'logging' => true,
Collector Conflicts:
time, router).php artisan cache:clear
Inspecting Blade Templates:
Event Debugging:
Illuminate\Events\Dispatcher).Memory Leaks:
memory_get_usage() in PHP for granular tracking.Custom Data Visualization:
resources/views/vendor/web-profiler/ (if using Laravel’s view system).Disabling Specific Collectors:
// config/profiler.php
'collectors' => [
'Symfony\Bundle\WebServerBundle\DataCollector\WebServerCollector' => false,
],
Profiler in API Tests:
use Symfony\Component\HttpKernel\Profiler\Profiler;
public function testApi() {
$profiler = new Profiler();
$profiler->enable();
$response = $this->get('/api/endpoint');
// Assertions using profiler data...
}
Laravel-Specific Workarounds:
symfony/http-kernel to integrate Symfony’s profiler:
composer require symfony/http-kernel
// app/Http/Middleware/ProfilerMiddleware.php
use Symfony\Component\HttpKernel\HttpKernelInterface;
public function handle($request, Closure $next) {
$kernel = new HttpKernel();
$response = $kernel->handle($request, HttpKernelInterface::MAIN_REQUEST);
return $response;
}
Security Note:
/_profiler/ in production. Use firewall rules to block access:
// routes/web.php
Route::middleware(['web', 'profiler'])->group(function () {
// Profiler routes
});
How can I help you explore Laravel packages today?