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 integrating XHProf profiling into your app. Capture and review performance data for requests, analyze bottlenecks, and compare runs to optimize code, queries, and overall response time with minimal setup and overhead.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Profiling Layer: Seamlessly integrates into Laravel’s middleware stack, enabling non-intrusive profiling of HTTP requests without modifying business logic. The facade-based API (Xhprof::start()/Xhprof::stop()) allows granular CLI/job instrumentation, making it suitable for full-stack performance analysis.
  • Storage Agnosticism: Supports database (default) and file storage, with extensibility for custom backends (e.g., S3). This aligns with Laravel’s modular design and avoids vendor lock-in.
  • Event-Driven: Emits ProfileSaved events, enabling post-processing (e.g., alerts, analytics) without coupling profiling logic to storage.
  • Laravel Ecosystem Compatibility: Built for Laravel 10–13.x, with service provider bootstrapping, configuration publishing, and migration support, ensuring zero-configuration for basic use cases.

Integration Feasibility

  • Low Friction: Requires only:
    1. XHProf PHP extension (must be pre-installed in PHP environment).
    2. Composer dependency (laracraft-tech/laravel-xhprof).
    3. Published config/migrations (php artisan vendor:publish).
    4. Middleware registration (optional, for auto-profiling).
  • Middleware Integration: Can be globally enabled (via Kernel.php) or selectively applied (e.g., only for /api/* routes). Supports URL-based exclusion (e.g., skip health checks).
  • CLI/Queue Support: Facade API enables manual profiling of Artisan commands, queue workers, and scheduled jobs, addressing non-HTTP bottlenecks.
  • Test Integration: Works with Laravel’s testing framework to enforce SLAs (e.g., fail tests if wall time > 500ms).

Technical Risk

Risk Mitigation Severity
XHProf Extension Missing Requires pre-flight check (`php -m grep xhprof`) in CI/CD. Provide fallback guidance (e.g., Docker setup with XHProf-enabled PHP image).
Database Bloat Default storage uses xhprof_runs table. Mitigate with: Medium
- Prune old profiles (php artisan xhprof:prune --days=30).
- Switch to file storage for high-volume profiling.
Middleware Order Issues Wall time may be incomplete if middleware runs after profiling starts. Solution: Place \LaracraftTech\Xhprof\Http\Middleware\Profile first in the web middleware group. Medium
Blob Truncation (MySQL) Fixed in v1.0.10+, but legacy DBs may need manual migration. Check: SHOW CREATE TABLE xhprof_runs for LONGTEXT data column. Low
CLI Overhead Profiling adds ~10–30% runtime overhead. Mitigate with: Low
- Use sampling (XHPROF_SAMPLE_RATE=10).
- Profile selectively (e.g., only critical jobs).
Production Usage Not recommended for production (overhead, storage impact). Solution: Gate via config/xhprof.php (enabled: env('APP_ENV') !== 'production'). High
Custom Storage Complexity Extending storage requires implementing Storage interface. Mitigate with: Medium
- Use file storage as a drop-in alternative.
- Provide starter template for S3/DB backends in docs.

Key Questions

  1. Environment Constraints:

    • Can XHProf be installed in all target environments (dev/staging/prod)? If not, how will profiling be gated (e.g., only local/staging)?
    • Are there shared hosting restrictions that prevent extension installation?
  2. Storage Strategy:

    • For high-traffic apps, will database storage scale? If not, will file storage or a custom backend (e.g., S3) be implemented?
    • What retention policy will be enforced for profiles (e.g., auto-prune after 30 days)?
  3. Profiling Scope:

    • Should profiling be auto-enabled for all routes (via middleware) or opt-in (e.g., ?profile=1)?
    • Are there specific CLI jobs/queues that require profiling? If so, how will they be instrumented?
  4. CI/CD Integration:

    • Will profiling be used to enforce SLAs in tests? If yes, what thresholds (e.g., wall time, memory) will trigger failures?
    • How will performance regressions be tracked across branches (e.g., compare flame graphs for main vs. feature/*)?
  5. Maintenance:

    • Who will monitor profile storage (DB/file) for bloat?
    • Will custom storage backends (e.g., S3) be developed, or will the default database/file storage suffice?
  6. Visualization:

    • Will profiles be exported to tools like Tideways/Blackfire for advanced analysis, or will the built-in /xhprof route suffice?
    • Are there plans to integrate with existing observability tools (e.g., Grafana, Datadog)?

Integration Approach

Stack Fit

  • Laravel 10–13.x: Native support with service providers, configuration publishing, and migration compatibility.
  • PHP Environment: Requires XHProf extension (must be pre-installed). Works with:
    • Web: Apache/Nginx with PHP-FPM.
    • CLI: Artisan commands, queue workers (queue:work), scheduled jobs (schedule:run).
  • Database: Supports MySQL, PostgreSQL, SQLite (via Laravel migrations). No schema changes required if using default table.
  • Storage: Defaults to database, but supports file storage (stored in storage/app/xhprof) and custom backends (via Storage interface).
  • Testing: Integrates with Laravel’s PHPUnit for performance assertions (e.g., assertLessThan(500, $profile->getWallTime())).

Migration Path

Phase Steps Dependencies Risks
Pre-Installation 1. Verify XHProf extension is installed (`php -m grep xhprof`). PHP environment setup.
2. Set XHPROF_SAMPLE_RATE in php.ini (e.g., 100 for full profiling, 10 for sampling). PHP config. Low.
Installation 1. Add package: composer require laracraft-tech/laravel-xhprof. Composer. Low.
2. Publish config/migrations: php artisan vendor:publish --tag=xhprof-config --tag=xhprof-migrations. Laravel CLI. Low.
3. Run migrations: php artisan migrate. Database. Medium (schema changes).
Configuration 1. Update config/xhprof.php to gate profiling (e.g., enabled: env('APP_ENV') !== 'production'). Config file. Low.
2. (Optional) Add middleware to app/Http/Kernel.php for auto-profiling: Laravel middleware. Low.
```php
protected $middlewareGroups = [
'web' => [
\LaracraftTech\Xhprof\Http\Middleware\Profile::class,
// ...
],
];
Testing 1. Test profiling via URL: `
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope