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

Lighthouse Php Laravel Package

spatie/lighthouse-php

Run Google Lighthouse audits from PHP. Test any URL and retrieve category scores (performance, accessibility, SEO, etc.) and individual audit details. Configure headers, user agent, categories, CPU throttling, and max load wait, then run and parse results.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Core Use Case Alignment: The package excels in server-side Lighthouse execution, enabling PHP/Laravel applications to programmatically audit web performance, accessibility, SEO, and PWA compliance. This aligns well with:
    • Backend-driven QA pipelines (e.g., CI/CD integration for automated audits).
    • Dynamic reporting (e.g., storing Lighthouse results in a database for trend analysis).
    • Headless browser automation (e.g., triggering audits post-deployment or via cron jobs).
  • Laravel Synergy: Leverages Laravel’s service container, queues, and task scheduling (e.g., Lighthouse::url() can be wrapped in a job for async execution). Complements existing Laravel tools like Laravel Horizon for queue monitoring.
  • Extensibility: Supports custom Chrome flags, throttling profiles, and result parsing, making it adaptable to niche requirements (e.g., mobile emulation, custom audit thresholds).

Integration Feasibility

  • Low Friction for Laravel: Designed for Laravel with zero-configuration setup (e.g., spatie/lighthouse-php + spatie/laravel-package-tools). Minimal boilerplate for basic usage.
  • Dependencies:
    • Chrome/Chromium: Requires a headless browser (e.g., Dockerized Chrome or system-level installation). May need orchestration for CI/CD environments.
    • PHP Extensions: No critical extensions, but exec() or shell_exec() is used to launch Chrome (security implications; see Technical Risk).
  • Result Handling: Returns structured data (JSON/XML) that can be serialized into Laravel models (e.g., LighthouseResult) or stored in databases like MySQL/PostgreSQL.

Technical Risk

  • Security:
    • Command Injection: Uses exec() to launch Chrome. Mitigation: Validate URLs, sanitize inputs, and restrict Chrome binary paths (e.g., via environment variables).
    • Resource Exhaustion: Lighthouse audits can consume significant CPU/memory. Risk of OOM crashes in shared hosting. Mitigation: Use queue workers with resource limits (e.g., Laravel Forge/Forge).
  • Environment Dependencies:
    • Chrome Versioning: Lighthouse requires specific Chrome versions. May need pinning (e.g., Docker images) to avoid compatibility breaks.
    • OS-Specific Paths: Chrome binary paths differ across Linux/Windows/macOS. Configuration management (e.g., .env) is critical.
  • Performance:
    • Audit Duration: Full audits (e.g., PWA checks) can take 30–120 seconds. Async execution (queues) is mandatory for production use.
    • Parallelization: No built-in support for concurrent audits. May require custom queue workers or external tools (e.g., Laravel Nova jobs).

Key Questions

  1. Use Case Clarity:
    • Will audits be triggered manually (e.g., admin dashboard), scheduled (cron), or event-driven (e.g., post-deploy hooks)?
    • Are results used for real-time feedback (e.g., Slack alerts) or historical analysis (e.g., database-backed dashboards)?
  2. Infrastructure Constraints:
    • Is Chrome pre-installed in CI/CD environments, or will Docker be required?
    • What are the resource limits for audit workers (CPU/memory)?
  3. Result Utilization:
    • How will Lighthouse data be stored/processed (e.g., Elasticsearch for trends, or simple Laravel models)?
    • Are there custom thresholds for failing audits (e.g., "block deploy if performance score < 90")?
  4. Scaling Needs:
    • Will audits be run at scale (e.g., 100+ URLs daily)? If so, consider distributed queue systems (e.g., Redis + Laravel Queues).
    • Are there plans to extend Lighthouse (e.g., custom audits, API integrations)?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Service Provider: Registers Lighthouse facade and binds the Lighthouse class to the container.
    • Queues: Ideal for async execution (e.g., LighthouseJob extending ShouldQueue).
    • Artisan Commands: Can wrap Lighthouse::url() in a custom command for CLI access (e.g., php artisan lighthouse:audit https://example.com).
    • Testing: Mockable for unit tests (e.g., LighthouseResult can be stubbed).
  • Complementary Packages:
    • Spatie’s Laravel Package Tools: Simplifies installation and configuration.
    • Laravel Nova: For UI-driven audit triggering/reporting.
    • Laravel Telescope: Monitor queue jobs and audit failures.
  • Non-Laravel PHP:
    • Works in vanilla PHP but lacks Laravel’s conveniences (e.g., queues, service container). Not recommended unless Laravel is a hard dependency.

Migration Path

  1. Proof of Concept (PoC):
    • Install via Composer: composer require spatie/lighthouse-php.
    • Test basic usage:
      $result = Lighthouse::url('https://example.com')->run();
      dd($result->performanceScore);
      
    • Validate Chrome environment (local/Docker/CI).
  2. Async Integration:
    • Create a job:
      use Spatie\Lighthouse\Jobs\RunLighthouse;
      RunLighthouse::dispatch('https://example.com')->onQueue('lighthouse');
      
    • Configure queue worker (e.g., Supervisor for Linux, Laravel Horizon).
  3. Result Processing:
    • Store results in a database:
      $result->toArray(); // Parse into a Laravel model
      
    • Or export to external systems (e.g., CSV, API).
  4. Monitoring:
    • Add Telescope logging for job failures.
    • Set up alerts (e.g., Slack via Laravel Notifications) for critical score drops.

Compatibility

  • Laravel Versions: Tested with Laravel 8+ (check Spatie’s docs for exact versions).
  • PHP Versions: Requires PHP 8.0+. No major compatibility issues expected.
  • Chrome/Chromium:
    • Minimum Version: Lighthouse v10+ requires Chrome 90+. Pin versions in Dockerfiles or CI (e.g., FROM chrome:stable).
    • Headless Mode: Enabled by default; no additional config needed.
  • Cross-Platform:
    • Linux: Native support (most CI/CD environments).
    • Windows/macOS: Works but may need path adjustments (e.g., CHROME_BINARY env var).

Sequencing

  1. Phase 1: Core Integration
    • Implement basic audit triggering (sync/async).
    • Store results in a simple table (e.g., lighthouse_results).
  2. Phase 2: Automation
    • Add cron jobs for scheduled audits (e.g., nightly).
    • Integrate with deploy hooks (e.g., GitHub Actions, Laravel Forge).
  3. Phase 3: Advanced Features
    • Build a dashboard (Nova/Livewire) for result visualization.
    • Add custom thresholds and alerting (e.g., "fail build if accessibility score < 85").
  4. Phase 4: Scaling
    • Optimize queue workers (e.g., batch processing, distributed workers).
    • Cache frequent audits (e.g., Redis) to avoid redundant runs.

Operational Impact

Maintenance

  • Package Updates:
    • Low Effort: Spatie maintains the package actively (releases ~quarterly). Updates are backward-compatible for minor versions.
    • Dependency Management: Monitor Chrome version requirements (e.g., Lighthouse v11 may need Chrome 100+).
  • Configuration Drift:
    • Centralize Chrome paths and flags in .env (e.g., LIGHTHOUSE_CHROME_BINARY=/usr/bin/chromium).
    • Document environment-specific setups (e.g., Docker vs. bare metal).
  • Deprecation Risk:
    • Lighthouse API: Google may deprecate underlying Lighthouse APIs. Monitor Lighthouse GitHub for changes.

Support

  • Troubleshooting:
    • Common Issues:
      • Chrome not found → Verify CHROME_BINARY env var or system PATH.
      • Timeout errors → Increase LIGHTHOUSE_TIMEOUT (default: 30s) or optimize audit scope.
      • Permission denied → Ensure queue workers have access to Chrome binary.
    • Debugging Tools:
      • Use Lighthouse::url()->debug() to log Chrome commands.
      • Check queue worker logs (e.g., Laravel Horizon) for failures.
  • Community Resources:
    • GitHub Discussions: Active for Spatie packages.
    • Stack Overflow: Limited but growing (tag spatie-lighthouse).
    • Spatie Docs: Comprehensive but assume some L
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
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
twbs/bootstrap4