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
Add to config/app.php under providers (Laravel 8+):
Symfony\Component\HttpKernel\Bundle\BundleInterface::class => [
Symfony\WebProfilerBundle\WebProfilerBundle::class,
],
Enable Debug Mode:
Set APP_DEBUG=true in .env and ensure APP_ENV=local:
APP_DEBUG=true
APP_ENV=local
First Use Case:
/ or run php artisan serve).X-Powered-By: Symfony)./_profiler/).Debugging HTTP Requests:
Performance Profiling:
->select() or caching.State Inspection:
QueryException in a controller).Request object in middleware).Custom Data Collection:
// app/Collectors/CustomCollector.php
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Illuminate\Support\Facades\Cache;
class CustomCollector extends DataCollector {
public function collect(Request $request, Response $response, \Throwable $exception = null) {
$this->data['cache_hits'] = Cache::stats()['hits'] ?? 0;
return $this->data;
}
public function getName() { return 'custom'; }
}
config/profiler.php (create if missing):
'collectors' => [
'custom' => App\Collectors\CustomCollector::class,
],
Integration with Laravel Features:
auth:api or throttle).Testing Workflows:
Profiler::enable() in PHPUnit tests to capture profiler data:
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Illuminate\Foundation\Testing\TestCase;
class FeatureTest extends TestCase {
protected function setUp(): void {
parent::setUp();
$profiler = app(Profiler::class);
$profiler->enable();
}
public function testApiEndpoint() {
$response = $this->get('/api/users');
$this->assertEquals(200, $response->status());
// Assert profiler data (e.g., query count)
$this->assertEquals(1, $profiler->getCollector('db')->getQueryCount());
}
}
Debug Toolbar Not Showing:
APP_DEBUG=true and APP_ENV=local.php artisan cache:clear and php artisan view:clear./_profiler/* in production:
// app/Http/Middleware/TrustProxies.php
protected $proxies = TrustedProxy::IP_ADDRESSES | '*'; // Allow profiler IPs
X-Powered-By: Symfony header is present (add to .htaccess or nginx.conf):
Header set X-Powered-By "Symfony"
Performance Overhead:
APP_DEBUG=false
--env=testing for tests to avoid profiler noise.Doctrine/Eloquent Queries Missing:
doctrine/dbal or laravel/framework (for Eloquent) is installed.config/database.php:
'logging' => true,
'logging_query' => true,
symfony/var-dumper for better query inspection:
composer require symfony/var-dumper
Collector Conflicts:
time, router).php artisan cache:clear.Profiler in API Tests:
HttpTests). Disable it in phpunit.xml:
<env name="APP_DEBUG" value="false"/>
Inspecting Blade/Twig Rendering:
@foreach loop in Blade).Event Dispatcher Debugging:
Illuminate\Events\Dispatcher).Memory Leaks:
memory_get_peak_usage() in PHP for granular tracking.Custom Data Visualization:
resources/views/vendor/web-profiler/ (Laravel 8+).Profiler in Queues/Jobs:
use Symfony\Component\HttpKernel\Profiler\Profiler;
public function handle() {
$profiler = app(Profiler::class);
$profiler->enable();
// Job logic...
}
/_profiler/{token}/jobs.Disabling Specific Collectors:
// config/profiler.php
'enabled_collectors' => [
'time', 'memory', 'exceptions', 'logger', 'request', 'router',
// Exclude 'doctrine' if not using DBAL/ORM
],
Profiler in Subrequests:
HttpClient or Cache::remember), but data is scoped to the parent request.Profiler::enable() explicitly for isolated subrequests.Production-Like Debugging:
APP_ENV=production with APP_DEBUG=true to test production configurations without toolbar noise./_profiler/ (disable in app/Http/Kernel.php if needed):
protected $middlewareGroups = [
'web' => [
// ...
\Symfony\Component\HttpKernel\Middleware\ProfilerMiddleware::class,
],
];
Laravel-Specific Adjustments:
bootstrap/app.php if profiler isn’t working:
$app->withRouting(
$app->router()->cache(function () { return false; }),
);
WebProfilerBundleHow can I help you explore Laravel packages today?