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 Dashboard Bundle Laravel Package

elao/profiler-dashboard-bundle

Symfony bundle that aggregates recent Symfony Profiler data (requests, timings, DB queries, etc.) into a single dashboard view, making it easier to compare and monitor performance across the last requests in dev/test environments.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle via Composer:

    composer require elao/profiler-dashboard-bundle
    

    Enable it in config/bundles.php:

    Elao\ProfilerDashboardBundle\ElaoProfilerDashboardBundle::class => ['all' => true],
    
  2. Configuration Publish the default config:

    php artisan vendor:publish --provider="Elao\ProfilerDashboardBundle\ElaoProfilerDashboardBundle" --tag="config"
    

    Verify config/elao_profiler_dashboard.php exists.

  3. First Use Case

    • Ensure Symfony Profiler is enabled (APP_DEBUG=true in .env).
    • Visit /_profiler and navigate to the "Profiler Dashboard" tab.
    • Observe compiled metrics (e.g., request times, memory usage) for the last N requests (configurable via max_requests in config).

Implementation Patterns

Workflows

  1. Monitoring Requests

    • Use the dashboard to track slow requests by sorting metrics (e.g., execution_time, memory_usage).
    • Filter by route, controller, or HTTP method via URL parameters (e.g., ?_route=api.users.index).
  2. Integration with Existing Tools

    • Logging: Export metrics to a log file via monolog by configuring logger_channel in the bundle config.
    • Alerting: Use Symfony’s EventDispatcher to trigger alerts when thresholds (e.g., max_execution_time) are exceeded:
      // In a service or listener
      $this->eventDispatcher->addListener(
          ElaoProfilerDashboardBundleEvents::REQUEST_PROFILED,
          function (RequestProfiledEvent $event) {
              if ($event->getExecutionTime() > 5000) {
                  // Trigger alert (e.g., Slack, Email)
              }
          }
      );
      
  3. Custom Metrics

    • Extend the profiler to include custom metrics (e.g., database query counts):
      // In a service or middleware
      $profiler = $this->container->get('profiler');
      $profiler->addCustomMetric('db_queries', $queryCount);
      
  4. Performance Regression Testing

    • Compare metrics across deployments by storing historical data in a database (requires custom implementation).

Integration Tips

  • Symfony Flex: If using Symfony Flex, ensure the bundle’s autoloading is compatible with your composer.json:
    "autoload": {
        "psr-4": {
            "": "src/",
            "Elao\\ProfilerDashboardBundle\\": "vendor/elao/profiler-dashboard-bundle/"
        }
    }
    
  • Caching: Disable caching for the profiler dashboard in config/packages/dev/profiler.yaml:
    framework:
        profiler:
            collect: true
    
  • Environment-Specific Config: Override settings per environment (e.g., config/elao_profiler_dashboard.php for prod):
    return [
        'max_requests' => 100, // Higher for production
        'enabled' => false,   // Disable in prod unless debugging
    ];
    

Gotchas and Tips

Pitfalls

  1. Deprecated Symfony Versions

    • The bundle was last updated in 2017 and may not support Symfony 5/6+. Test thoroughly or fork the package.
    • Workaround: Use a compatibility layer like symfony/polyfill or patch the bundle manually.
  2. Memory Overhead

    • Storing metrics for many requests (max_requests) increases memory usage. Monitor with:
      php artisan cache:clear && php artisan config:clear
      
    • Tip: Set max_requests to a reasonable limit (e.g., 50) in production.
  3. Profiler Disabled in Production

    • The dashboard will not appear if APP_DEBUG=false. Use a feature flag or middleware to enable it conditionally:
      // In a middleware
      if ($request->ip() === 'YOUR_IP' && !$this->container->getParameter('kernel.debug')) {
          $this->container->setParameter('kernel.debug', true);
      }
      
  4. Database Backend Issues

    • The bundle assumes a default Doctrine setup. If using a non-standard database, configure database_connection in the config:
      return [
          'database_connection' => 'pgsql', // Override if not using default
      ];
      

Debugging

  • Missing Dashboard Tab:

    • Verify the bundle is enabled in config/bundles.php.
    • Check for errors in var/log/dev.log (Symfony’s default log location).
    • Ensure the profiler is collecting data (APP_DEBUG=true).
  • Metrics Not Updating:

    • Clear the profiler cache:
      php artisan cache:clear
      
    • Check if the profiler service is bound correctly in the container.
  • Custom Metrics Not Displaying:

    • Ensure metrics are added before the request completes:
      $profiler->addCustomMetric('key', $value); // Must be called during request lifecycle
      

Extension Points

  1. Custom Storage Backend

    • Override the storage logic by binding a custom service to elao_profiler_dashboard.storage:
      # config/services.yaml
      services:
          App\Service\CustomProfilerStorage:
              tags: ['elao_profiler_dashboard.storage']
      
  2. Modify Metric Calculation

    • Extend the Elao\ProfilerDashboardBundle\Profiler\Profiler class to add/override metrics:
      class CustomProfiler extends \Elao\ProfilerDashboardBundle\Profiler\Profiler
      {
          public function getCustomMetric()
          {
              return $this->customLogic();
          }
      }
      
    • Bind it in config/services.yaml:
      services:
          Elao\ProfilerDashboardBundle\Profiler\Profiler:
              class: App\Profiler\CustomProfiler
      
  3. UI Customization

    • Override the Twig templates by publishing and modifying them:
      php artisan vendor:publish --provider="Elao\ProfilerDashboardBundle\ElaoProfilerDashboardBundle" --tag="templates"
      
    • Place custom templates in templates/bundles/elaoprofilerdashboard/.
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware