aeatech / snapshot-profiler-xhprof
Snapshot profiler xhprof
Installs: 15
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/aeatech/snapshot-profiler-xhprof
Requires
- php: >=8.2
- ext-xhprof: *
- aeatech/snapshot-profiler: ^1.0
- perftools/php-profiler: ^1.2
Requires (Dev)
- mockery/mockery: ^1.6
- phpunit/phpunit: ^11.5
- roave/security-advisories: dev-master
This package is not auto-updated.
Last update: 2025-12-19 14:22:22 UTC
README
The package contains implementation of aeatech/snapshot-profiler-contracts to profile applications with xhprof. It can be used for production profiling.
System requirements:
- PHP >= 8.2
- ext-xhprof
- xhgui (tested on xhgui/xhgui:0.22.1)
Installation (Composer):
composer require aeatech/snapshot-profiler-xhprof
Quick start
<?php declare(strict_types=1); use AEATech\SnapshotProfiler\Profiler; use AEATech\SnapshotProfilerXhprof\Adapter; use AEATech\SnapshotProfilerXhprof\Saver; use Xhgui\Profiler\Profiler as BackendProfiler; use Xhgui\Profiler\ProfilingFlags; require_once 'vendor/autoload.php'; /** * Start initialization */ $profilerConfig = [ 'profiler' => BackendProfiler::PROFILER_XHPROF, 'profiler.flags' => [ ProfilingFlags::MEMORY, ], 'save.handler' => BackendProfiler::SAVER_UPLOAD, 'save.handler.upload' => [ 'uri' => 'http://xhgui:80/run/import', 'timeout' => 1, ], ]; $backendProfiler = new BackendProfiler($profilerConfig); $saver = new Saver($backendProfiler); $adapterIniSettings = [ 'xhprof.collect_additional_info' => '1', ]; $adapter = new Adapter($backendProfiler, $adapterIniSettings); $profiler = new Profiler($adapter); $profilingOptions = []; /** * End initialization */ /** * Start profiling */ $profiler->enable(); /** * It's doing nothing and added for backward compatibility with newrelic */ $profiler->setProfilingOptions($profilingOptions); for ($i = 0; $i < 10; $i++) { random_int(1, 10); } $data = $profiler->disable(); /** * End profiling */ /** * Start customization (not necessarily) */ /** * If you use fpm it will take current URL as snapshot name * If you use cli it will take script.php as snapshot name * Example of custom snapshot name */ $data[Adapter::KEY_META][Adapter::KEY_META_URL] = '1.0.0|serviceName|env|snapshotName'; /** * Set snapshot timestamps (usable for cli processes) */ $dateTime = new DateTime(); $timestamp = $dateTime->getTimestamp(); $data[Adapter::KEY_META][Adapter::KEY_META_REQUEST_TS_MICRO] = [ Adapter::KEY_META_REQUEST_TS_MICRO_SEC => $timestamp, Adapter::KEY_META_REQUEST_TS_MICRO_USEC => $dateTime->format('u'), ]; $data[Adapter::KEY_META][Adapter::KEY_META_SERVER][Adapter::KEY_META_SERVER_REQUEST_TIME] = $timestamp; $data[Adapter::KEY_META][Adapter::KEY_META_SERVER][Adapter::KEY_META_SERVER_REQUEST_TIME_FLOAT] = $dateTime->format('U.u'); /** * End customization */ /** * Save profiling result */ $saver->save($data); /** * http://127.0.0.1:8142 - profile results here */
License
MIT License. See LICENSE for details.