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

Profiler Pack Laravel Package

symfony/profiler-pack

Symfony Profiler Pack integrates the Symfony Profiler and Web Debug Toolbar into your app, giving detailed request/response insights, performance metrics, logs, and debugging panels. Ideal for local dev and troubleshooting during development.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require symfony/profiler-pack
    
    • Works seamlessly with Symfony Flex (auto-configures for Symfony 4.4+).
    • For older Symfony versions, manually enable the web_profiler bundle in config/bundles.php.
  2. First Use Case:

    • Debug a Controller: Access /_profiler/ (or /_wdt for Web Debug Toolbar) after a request.
    • View Data Collectors: Click the "Profiler" tab to inspect:
      • Request/response details
      • Doctrine queries (if doctrine/doctrine-bundle is installed)
      • Twig template rendering times
      • Cache statistics
  3. Key Files to Review:

    • config/packages/dev/web_profiler.yaml (default configuration).
    • var/cache/dev/app_profiler.php (generated profiler data).

Implementation Patterns

Core Workflows

  1. Debugging Requests:

    • Use the Web Debug Toolbar (top-right corner) to:
      • Toggle profiler visibility (?_profiler=1).
      • Filter by request method/URI.
    • Example: Add ?_error_handler=1 to see uncaught exceptions in detail.
  2. Custom Data Collectors:

    • Extend Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface:
      // src/DataCollector/MyCollector.php
      class MyCollector implements DataCollectorInterface {
          public function collect(Request $request, Responder $responder, \Exception $exception = null) {
              $this->data['custom_metric'] = microtime(true);
          }
          public function getName() { return 'my_collector'; }
          public function get() { return $this->data; }
      }
      
    • Register in config/services.yaml:
      services:
          App\DataCollector\MyCollector:
              tags: ['data_collector']
      
  3. Integration with Tests:

    • Use Symfony\Bundle\DebugBundle\DataCollector\RouterDataCollector in PHPUnit:
      $client = static::createClient();
      $client->request('GET', '/');
      $profiler = $client->getProfile();
      $this->assertEquals(200, $profiler->getResponse()->getStatusCode());
      
  4. Performance Profiling:

    • Timeline View: Analyze request execution flow (e.g., Doctrine queries, Twig rendering).
    • Memory Usage: Check memory tab for leaks (e.g., during bulk operations).
  5. Environment-Specific Setup:

    • Disable in production (config/packages/prod/web_profiler.yaml):
      web_profiler: false
      

Gotchas and Tips

Pitfalls

  1. Performance Overhead:

    • Profiler adds ~10-30ms per request. Disable in staging/prod:
      # config/packages/prod/web_profiler.yaml
      web_profiler: false
      stoplight: false
      
  2. Caching Issues:

    • Clear cache after adding custom collectors:
      php bin/console cache:clear
      
    • Profiler data is stored in var/cache/dev/app_profiler.php (delete manually if corrupted).
  3. Router Conflicts:

    • Avoid naming routes /_profiler or /_wdt (profiler routes are auto-registered).
    • Fix: Use _profiler as a query parameter (?_profiler=1) instead of a route.
  4. Doctrine DataCollector Missing:

    • Requires doctrine/doctrine-bundle and doctrine/orm:
      composer require doctrine/doctrine-bundle
      
  5. CSRF Token Errors:

    • Profiler toolbar may fail if CSRF protection is enabled. Exclude /_profiler in config/packages/security.yaml:
      access_control:
          - { path: ^/_profiler, roles: IS_AUTHENTICATED_ANONYMOUSLY }
      

Debugging Tips

  1. Enable Verbose Logging:

    php bin/console debug:config symfony.web_profiler
    
    • Check web_profiler.enabled and stoplight.enabled.
  2. Inspect Collectors:

    • List available collectors:
      php bin/console debug:container --tag=data_collector
      
  3. Profiler Not Showing:

    • Ensure APP_ENV=dev in .env.
    • Check var/cache/dev/app_profiler.php exists (regenerate with cache:clear).
  4. Custom Collector Not Displaying:

    • Verify the collector implements all required methods (collect(), getName(), get()).
    • Check Symfony’s event dispatcher logs for errors.

Extension Points

  1. Override Profiler Templates:

    • Copy vendor/symfony/web-profiler-bundle/Resources/views/ to templates/bundles/webprofiler/ and override (e.g., toolbar.html.twig).
  2. Add Profiler to API Responses:

    • Use Symfony\Component\HttpFoundation\Response::setProfilerData():
      $response = new Response();
      $response->setProfilerData(['custom' => 'data']);
      
  3. Integrate with Blackfire:

    • Install blackfire/php-profiler and configure web_profiler to use Blackfire’s data:
      web_profiler:
          blackfire: true
      
  4. Custom Profiler Storage:

    • Extend Symfony\Component\HttpKernel\DataCollector\Storage\PhpFileStorage to log data to a database or external service.
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui