Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Web Profiler Bundle Laravel Package

symfony/web-profiler-bundle

Symfony WebProfilerBundle integrates the Symfony Profiler into your app, showing debug and performance insights via the web debug toolbar and profiler pages. Inspect requests, routes, logs, DB queries, caching, events, and more to troubleshoot faster.

Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require symfony/web-profiler-bundle
    

    Add to config/bundles.php (Symfony 5+):

    return [
        // ...
        Symfony\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
    ];
    
  2. Enable Debug Mode: Set APP_DEBUG=true in .env (or config/packages/dev.php for Symfony 5+):

    APP_DEBUG=1
    APP_ENV=dev
    
  3. First Use Case:

    • Trigger a request (e.g., visit / or run php bin/console server:run).
    • Observe the Debug Toolbar at the bottom of the page, showing:
      • Request time, memory usage, and HTTP status.
      • Click the toolbar to open the Profiler (/_profiler/).
    • Inspect default panels like Requests, Time, Router, and Doctrine (if using DBAL/ORM).

Implementation Patterns

Core Workflows

  1. Debugging Requests:

    • Use the Requests panel to compare current vs. previous requests (e.g., after refactoring).
    • Filter by URL, method, or status code to isolate issues.
  2. Performance Profiling:

    • Timeline panel visualizes execution flow (e.g., controller → service → DB calls).
    • Sort by duration to identify slow components (e.g., N+1 queries, heavy services).
    • Example: Click a DB query in Doctrine to see its SQL and execution time.
  3. State Inspection:

    • Response panel: Inspect headers, cookies, or rendered content (e.g., debug API responses).
    • Exceptions panel: Review uncaught errors with stack traces and context.
  4. Custom Data Collection:

    • Create a DataCollector to log custom metrics (e.g., third-party API calls):
      // src/Collector/MyCustomCollector.php
      use Symfony\Component\HttpKernel\DataCollector\DataCollector;
      
      class MyCustomCollector extends DataCollector {
          public function collect(Request $request, Response $response, \Throwable $exception = null) {
              $this->data['api_calls'] = $this->trackApiCalls();
              return $this->data;
          }
      
          public function getName() { return 'my_custom'; }
      }
      
    • Register in config/packages/dev.php:
      framework:
          profiler:
              collectors:
                  my_custom: App\Collector\MyCustomCollector
      
  5. Integration with Tests:

    • Use Profiler::enable() in PHPUnit tests to capture profiler data:
      use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
      
      class MyTest extends WebTestCase {
          public function testSomething() {
              $client = static::createClient();
              $client->request('GET', '/');
              $profiler = static::getContainer()->get('profiler');
              $profiler->collect($client->getInternalRequest(), $client->getInternalResponse());
              // Assertions using profiler data...
          }
      }
      

Gotchas and Tips

Pitfalls

  1. Debug Toolbar Not Showing:

    • Ensure APP_DEBUG=1 and APP_ENV=dev.
    • Clear cache: php bin/console cache:clear.
    • Check for middleware blocking the toolbar (e.g., CORS or security middleware). Exclude /_profiler/* in production.
  2. Performance Overhead:

    • The profiler adds ~10-20% overhead in development. Disable in CI/staging:
      APP_DEBUG=0
      
    • Use --env=test for tests to avoid profiler noise.
  3. Doctrine Queries Missing:

    • Ensure doctrine:dbal or doctrine:orm is installed and configured.
    • For custom repositories, enable SQL logging in config/packages/dev/dbal.php:
      dbal:
          logging: true
      
  4. Collector Conflicts:

    • Avoid naming custom collectors after built-in ones (e.g., time, router).
    • Clear cache after adding new collectors.

Debugging Tips

  1. Inspecting Twig Rendering:

    • Use the Twig panel to see template hierarchy and timing for each block.
    • Click a template to debug variable dumps.
  2. Event Dispatcher Debugging:

    • The Events panel lists all dispatched events with their listeners and execution order.
    • Useful for debugging middleware or event subscriber issues.
  3. Memory Leaks:

    • Monitor the Memory panel across requests to spot growing memory usage.
    • Compare with memory_get_usage() in PHP for granular tracking.
  4. Custom Data Visualization:

    • Extend the profiler UI by overriding templates in templates/bundles/webprofiler/ (Symfony 4+).
    • Example: Add a chart for your custom collector’s data using Twig.

Configuration Quirks

  1. Disabling Specific Collectors:

    # config/packages/dev/profiler.yaml
    framework:
        profiler:
            enabled: true
            collectors:
                'Symfony\Bundle\WebServerBundle\DataCollector\WebServerCollector': false
    
  2. Profiler in Subrequests:

    • The profiler works for subrequests (e.g., from Renderer or HttpClient), but data is scoped to the parent request.
    • Use Profiler::enable() explicitly for isolated subrequests.
  3. Production-Like Debugging:

    • Use APP_ENV=prod with APP_DEBUG=1 to test production configurations without toolbar noise.
    • Access profiler via /_profiler/ (disable in firewalls if needed):
      security:
          firewalls:
              dev:
                  pattern: ^/(_(profiler|wdt)|css|images|js)/
                  security: false
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport