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.
XHPROF_SAMPLE_RATE), ideal for development/staging environments where profiling overhead is acceptable.ProfileSaved events, enabling post-processing (e.g., alerts, integrations). Complements Laravel’s event ecosystem for observability.v1.0.10 fixes MySQL blob truncation). Uses Laravel’s service container and facades, reducing adoption friction.xhprof.so), a hard dependency but critical for profiling. Must be enabled in both CLI and web PHP configurations.php artisan vendor:publish).extension=xhprof.so in php.ini).
No custom routes/controllers needed for basic usage.APP_ENV=staging).| 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. |
xhprof.so), which must be enabled in:
php.ini for Apache/Nginx).php.ini for Artisan).Dockerfile).php -m | grep xhprof.composer require laracraft-tech/laravel-xhprof
php artisan vendor:publish --provider="LaracraftTech\Xhprof\XhprofServiceProvider"
config/xhprof.php.app/Http/Kernel.php:
protected $middleware = [
\LaracraftTech\Xhprof\Http\Middleware\Profile::class,
];
php artisan migrate (or publish migrations if customizing schema).http://app.test/route?profile=1.xhprof_runs table or storage directory.$this->assertLessThan(300, Xhprof::stop()->getWallTime(), "API too slow!");
php artisan queue:work --profile)./api/orders, /checkout).php artisan xhprof:prune).xhprof.so is loaded (php -m).Kernel.php order and Laravel logs.XHPROF_SAMPLE_RATE=10).How can I help you explore Laravel packages today?