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.
Xhprof::start()/Xhprof::stop()) allows granular CLI/job instrumentation, making it suitable for full-stack performance analysis.ProfileSaved events, enabling post-processing (e.g., alerts, analytics) without coupling profiling logic to storage.laracraft-tech/laravel-xhprof).php artisan vendor:publish).Kernel.php) or selectively applied (e.g., only for /api/* routes). Supports URL-based exclusion (e.g., skip health checks).| 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. |
Environment Constraints:
local/staging)?Storage Strategy:
Profiling Scope:
?profile=1)?CI/CD Integration:
main vs. feature/*)?Maintenance:
Visualization:
/xhprof route suffice?queue:work), scheduled jobs (schedule:run).storage/app/xhprof) and custom backends (via Storage interface).assertLessThan(500, $profile->getWallTime())).| 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: ` |
How can I help you explore Laravel packages today?