aferrandini/xhprof-bundle
Laravel-friendly integration of XHProf profiling: collect and view performance data for your app, track request timings and call graphs, and store runs for comparison. Useful for spotting bottlenecks in production-like environments.
Illuminate\Container) is incompatible without heavy refactoring.xhprof_lib/utils/xhprof_lib.php.xhprof_enable(), xhprof_disable()).xhprof_runs()), requiring custom logic for visualization (e.g., integrating with Grafana or custom dashboards).pecl/xhprof must be installed (pecl install xhprof).xhprof extension compatibility with the target PHP version.xhprof extension:
pecl install xhprof
Add to php.ini:
extension=xhprof.so
composer.json:
"require": {
"ext-xhprof": "*"
}
// app/Providers/XhprofServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class XhprofServiceProvider extends ServiceProvider {
public function boot() {
if (!extension_loaded('xhprof')) return;
\XHProf::enable(XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);
}
}
// app/Http/Middleware/ProfileRequests.php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Storage;
class ProfileRequests {
public function handle($request, Closure $next) {
$response = $next($request);
if (\XHProf::isEnabled()) {
$data = \XHProf::getInclusive();
$runId = \XHProf::getRunID();
Storage::put("xhprof/{$runId}.xhprof", serialize($data));
}
return $response;
}
}
xhprof_runs() to parse data and integrate with tools like:
xhprof and potentially eaccelerator/APCu for caching (optional).xhprof and test basic profiling in a staging environment.xhprof extension; migrating to another tool (e.g., Blackfire) would require re-architecting.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| XHProf extension missing/broken | Profiling fails silently | Automated health checks, fallback logs |
| PHP version incompatibility | Bundle/middleware crashes | Test in staging; use PHP 7.4 compatibility patches |
| Storage backend failures | Profiling data lost | Redundant storage (e.g., S3 + local) |
| High profiling overhead | Degraded performance | Disable in production; use selectively |
| Custom visualization breaks | Data unreadable | Export raw data (e.g., JSON) for analysis |
xhprof_enable(), xhprof_disable(), xhprof_runs()).How can I help you explore Laravel packages today?