perftools/xhgui-collector
Standalone XHProf data collector for storing profiles compatible with XHGUI (0.2–0.9). Supports PHP 5.3+, minimal dependencies, configurable storage/collection. Use via auto_prepend_file (web) or header for CLI. Being phased out; use perftools/php-profiler for new installs.
Architecture Fit
The perftools/xhgui-collector package is a legacy but functional tool for integrating XHProf profiling data into a Laravel application via MongoDB storage. While Laravel’s ecosystem has evolved toward modern observability tools (e.g., Laravel Telescope, Blackfire, or Tideways), this package offers a lightweight, customizable alternative for teams already invested in XHGUI or needing low-overhead profiling. Key architectural considerations:
auto_prepend_file or manual inclusion, which can conflict with Laravel’s bootstrap process (e.g., bootstrap/app.php). Requires careful placement in the service provider lifecycle (e.g., register() vs. boot()).Integration Feasibility
Kernel.php) or service providers, but requires manual setup of MongoDB connections and XHGUI configuration.XHGUI_MONGO_URI, XHGUI_PROFILING_RATIO, etc., reducing hardcoded dependencies.Technical Risk
PROFILING_RATIO=100) may impact performance.PROFILING_RATIO (e.g., 10) to sample requests.Key Questions
header.php) to avoid conflicts with Laravel’s service providers?perftools/php-profiler. Should we migrate to a maintained alternative (e.g., Tideways)?dd(), telescope) or SaaS?Stack Fit
laravel-profiler package). Requires manual setup.mu-plugins or functions.php hooks.Migration Path
PROFILING_RATIO) is sufficient or if full profiling is needed.XHGUI_MONGO_URI (e.g., mongodb://xhgui:27017).auto_prepend_file (Global)
Add to php.ini or .user.ini:
auto_prepend_file = "/path/to/vendor/perftools/xhgui-collector/external/header.php"
Risk: Affects all requests, including non-profiled routes.header.php only for profiled routes:
// app/Http/Middleware/Profile.php
public function handle($request, Closure $next) {
if ($request->isProfiled()) { // Custom logic
require __DIR__.'/../../vendor/perftools/xhgui-collector/external/header.php';
}
return $next($request);
}
header.php in a custom service provider:
// app/Providers/ProfileServiceProvider.php
public function boot() {
if ($this->app->runningInConsole()) {
require __DIR__.'/../../vendor/perftools/xhgui-collector/external/header.php';
}
}
export XHGUI_MONGO_DB=xhprof
export XHGUI_PROFILING_RATIO=10 # Profile 10% of requests
export XHGUI_PROFILING=enabled
XHGUI_PROFILING_RATIO=100 to ensure data is collected.xhprof by default).Compatibility
alcaeus/mongo-php-adapter (Composer dependency).mongo extension (v1.3.0+).pecl install xhprof).tideways_xhprof extension (commercial).Sequencing
PROFILING_RATIO=10./api/v1/*) via middleware.PROFILING_RATIO (e.g., 10 → 50).Maintenance
XHGUI_* variables in environment files (How can I help you explore Laravel packages today?