aeatech/snapshot-profiler-xhprof
最新稳定版本:1.0.0
Composer 安装命令:
composer require aeatech/snapshot-profiler-xhprof
包简介
Snapshot profiler xhprof
README 文档
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.
统计信息
- 总下载量: 28
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-18