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

Laravel Xhprof Laravel Package

laracraft-tech/laravel-xhprof

Laravel package to integrate XHProf profiling into your app. Capture and store performance profiles for requests and jobs, view results via a simple UI, and analyze bottlenecks to optimize code and database queries.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Profiling Layer: Fits Laravel’s middleware stack natively, enabling non-intrusive request/CLI profiling without architectural changes. Leverages XHProf’s low-overhead sampling (configurable via XHPROF_SAMPLE_RATE), ideal for development/staging environments where profiling overhead is acceptable.
  • Storage Flexibility: Supports database (default) and file-based storage, aligning with Laravel’s modularity. Extensible for custom backends (e.g., S3), though database storage risks schema bloat if not managed.
  • Event-Driven Design: Emits ProfileSaved events, enabling post-processing (e.g., alerts, integrations). Complements Laravel’s event ecosystem for observability.
  • Middleware-Based: Captures full request lifecycles, including framework overhead (e.g., route resolution), unlike tools focused solely on SQL or HTTP layers.

Integration Feasibility

  • Laravel 10–13.x Support: Actively maintained with backward-compatible migrations (e.g., v1.0.10 fixes MySQL blob truncation). Uses Laravel’s service container and facades, reducing adoption friction.
  • XHProf Dependency: Requires the PHP extension (xhprof.so), a hard dependency but critical for profiling. Must be enabled in both CLI and web PHP configurations.
  • Minimal Setup: Requires:
    1. Composer install.
    2. Publishing config/migrations (php artisan vendor:publish).
    3. Enabling the extension (extension=xhprof.so in php.ini). No custom routes/controllers needed for basic usage.
  • Selective Profiling: Supports route skipping (e.g., health checks) and environment-based gating (e.g., APP_ENV=staging).

Technical Risk

Risk Mitigation
XHProf Extension Unavailable Pre-integration validation via `php -m
Database Bloat Use file storage for high-volume profiling or implement TTL-based pruning (php artisan xhprof:prune). Monitor xhprof_runs table growth in staging.
Middleware Order Issues Place \LaracraftTech\Xhprof\Http\Middleware\Profile early in Kernel.php to capture full wall time. Verify timing accuracy with microtime(true) benchmarks.
CLI Profiling Overhead Configure XHPROF_SAMPLE_RATE=10 (10% sampling) for CLI jobs. Avoid profiling in production CI/CD pipelines.
Blob Data Truncation (MySQL) Run latest migration (v1.0.10+) for LONGTEXT columns. For existing tables, manually alter schema or switch to file storage.
Storage Scaling For large-scale profiling, implement partitioned database tables or S3-based storage via custom backend.

Key Questions

  1. Environment Support: Is XHProf enabled in all target environments (local, staging, CI)? If not, can it be installed?
  2. Storage Strategy: Will profiling data be stored in database or files? If database, what’s the retention policy?
  3. Performance Overhead: What’s the acceptable profiling overhead (e.g., 5%–10% wall time increase) for staging?
  4. CI/CD Integration: Should profiling be gated in tests (e.g., fail if API response > 300ms)?
  5. CLI/Queue Profiling: Are Artisan commands and queues critical profiling targets? If so, how will sampling rates be configured?
  6. Production Readiness: Will profiling ever run in production? If so, how will sampling rates and data retention be managed?
  7. Team Adoption: How will developers be trained to interpret flame graphs and act on profiling data?

Integration Approach

Stack Fit

  • Laravel 10–13.x: Native compatibility with middleware, service providers, and Artisan commands. No breaking changes in recent versions.
  • PHP Extensions: Requires XHProf (xhprof.so), which must be enabled in:
    • Web server (php.ini for Apache/Nginx).
    • CLI (php.ini for Artisan).
    • Docker/containerized environments (add to Dockerfile).
  • Database Support: Defaults to MySQL/PostgreSQL, but schema is simple (can be adapted for SQLite or custom storage).
  • Storage Alternatives: Supports file-based storage (configurable) for environments where database writes are costly.

Migration Path

  1. Pre-Integration Check:
    • Verify XHProf extension: php -m | grep xhprof.
    • Test extension in staging environment (CLI and web).
  2. Installation:
    composer require laracraft-tech/laravel-xhprof
    php artisan vendor:publish --provider="LaracraftTech\Xhprof\XhprofServiceProvider"
    
  3. Configuration:
    • Publish config: config/xhprof.php.
    • Enable middleware in app/Http/Kernel.php:
      protected $middleware = [
          \LaracraftTech\Xhprof\Http\Middleware\Profile::class,
      ];
      
    • Configure storage (database or files) and sampling rates.
  4. Database Migration:
    • Run php artisan migrate (or publish migrations if customizing schema).
  5. Testing:
    • Profile a test route: http://app.test/route?profile=1.
    • Verify data in xhprof_runs table or storage directory.
  6. CI/CD Integration (Optional):
    • Add performance tests:
      $this->assertLessThan(300, Xhprof::stop()->getWallTime(), "API too slow!");
      

Compatibility

  • Laravel Versions: Tested on 10.x–13.x. No known conflicts with popular packages (e.g., Laravel Debugbar, Telescope).
  • PHP Versions: Requires PHP 8.0+ (XHProf compatibility).
  • Database Drivers: Supports MySQL, PostgreSQL, SQLite (schema may need adjustments for SQLite).
  • Queue Workers: Profiling works for Laravel queues (e.g., php artisan queue:work --profile).

Sequencing

  1. Phase 1 (1 Sprint):
    • Install and configure in staging.
    • Profile 2–3 critical endpoints (e.g., /api/orders, /checkout).
    • Train team on reading flame graphs.
  2. Phase 2 (1 Sprint):
    • Integrate with CI/CD (performance gates).
    • Profile CLI jobs and queues.
  3. Phase 3 (Ongoing):
    • Expand to feature branches for regression testing.
    • Optimize based on data (e.g., query tuning, caching).

Operational Impact

Maintenance

  • Low Overhead: No active maintenance required after setup. Updates are minor (e.g., Laravel version compatibility).
  • Dependency Management:
    • Monitor XHProf PHP extension updates (security patches).
    • Watch for Laravel major version changes (e.g., 14.x support).
  • Storage Management:
    • Database: Implement TTL-based pruning or partitioned tables for long-term use.
    • Files: Configure automatic cleanup (e.g., php artisan xhprof:prune).

Support

  • Troubleshooting:
    • Extension Issues: Verify xhprof.so is loaded (php -m).
    • Middleware Failures: Check Kernel.php order and Laravel logs.
    • Storage Errors: Validate database permissions or file write access.
  • Community Support:
    • GitHub Issues: Active maintainers (235 stars, recent releases).
    • Documentation: Basic but sufficient for setup. May need internal runbooks for advanced use cases.
  • Fallback Options:
    • Blackfire or Tideways if XHProf is unavailable.
    • Laravel Debugbar for lightweight HTTP/SQL profiling.

Scaling

  • Profiling Volume:
    • Database Storage: Risk of table bloat with high-volume profiling. Mitigate with:
      • Sampling rates (XHPROF_SAMPLE_RATE=10).
      • File storage for staging/production.
      • Partitioned tables (e.g., by date).
    • File Storage: Scales better but requires disk space management.
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata