imhelle/yii2-xhprof-lib
Composer 安装命令:
composer require imhelle/yii2-xhprof-lib
包简介
Simple extension to profile Yii Framework 2.x applications with XHProf
关键字:
README 文档
README
Simple extension to use XHProf with Yii Framework 2.x. This is the updated version of yii-xhprof extension for Yii Framework 1.x.
Bundled with debug panel for official yii2-debug extension.
By default profile starts during bootstrap process and stops in PHP shutdown function. You can change this behavior and manually start and stop profiler.
Tested on Yii Framework v2.0.6+.
Xhprof installation
(CentOS)
sudo yum install gcc
cd /www/biglion/general/data/lib/vendor/imhelle/yii2-xhprof-lib/lib/
phpize
./configure
make
make test
sudo make install
sudo yum install graphviz
Yii extension installation
This extension is available at packagist.org and can be installed via composer by following command:
composer require --dev imhelle/yii2-xhprof.
Minimal configuration to enable profiler:
return [ 'bootstrap' => [ 'xhprof' ], 'components' => [ 'xhprof' => [ 'class' => 'imhelle\xhprof\XHProfComponent', 'libPath' => '/full/path/to/xhprof_lib', 'htmlReportBaseUrl' => 'http://url.to/xhprof_html', ], ], ];
To use bundled debug panel - update configuration next way:
return [ 'bootstrap' => [ 'debug', 'xhprof' ], 'components' => [ 'debug' => [ // ... other debug config options ... 'panels' => [ 'xhprof' => [ 'class' => 'imhelle\xhprof\XHProfPanel' ] ] ], ], ];
Note: xhprof should be after debug in preload section to be able to ignore requests to debug module pages.
Required XHProf files (library files - xhprof_lib and UI - xhprof_html) you can find in this GitHub repo.
Component configuration
Extension provide next configuration options for Yii component:
enabled- enable/disable profiler component.reportPath- filesystem path or path alias to the directory to store JSON file with previous profiler runs. Default:@runtime/xhprofmaxReportsCount- number of profile reports to store. Default:25.autoStart- flag to automatically start profiler during application bootstrap process. Default:true.autoStop- flag to automatically stop profiler in PHP shutdown function. Default:true.forceStop- flag to force stop profiler during PHP shutdown ifautoStopis disabled and profiler was manually started and is still running. Default:true.triggerGetParam- name of the GET param to manually trigger profiler to start. Default: no value, profiler runs on each request.showOverlay- flag to display overlay on page with links to report and callgraph result for current profiler run (if allowed). Not required to betrueif you are using bundled panel for yii2-debug extension. Default:true.libPath- direct filesystem path or path alias to the directory withxhprof_libcontents.htmlReportBaseUrl- URL path to the directory with XHProf UI contents (xhprof_html). Default:/xhprof_html(assuming you have this folder inside your document root).flagNoBuiltins- enable/disable XHPROF_FLAGS_NO_BUILTINS flag for profiler (XHProf constants). Default:true.flagCpu- enable/disable XHPROF_FLAGS_CPU flag for profiler (XHProf constants). Default:false.flagMemory- enable/disable XHPROF_FLAGS_MEMORY flag for profiler (XHProf constants). Default:true.ignoredFunctions- list of functions to ignore during profiling. Empty by default. Note: this option is not supported bytideways_xhprofextension.blacklistedRoutes- list of routes which profiler should ignore. Allowed wildcard*which means 'any alphanumeric value and one of this:/,.,_,-. Default:['debug*'](to ignore requests to the debug extension pages).
XHProf class configuration
Component from extension use own developed simple wrapper for xhprof_enable / xhprof_disable functions: XHProf class. This class provide functionality to start/stop profiling, save reports and get URLs for reports with XHProf library by Facebook.
Available configuration options (applicable for configure method, see example below):
flagNoBuiltins- enable/disable XHPROF_FLAGS_NO_BUILTINS flag for profiler (XHProf constants). Default:true.flagCpu- enable/disable XHPROF_FLAGS_CPU flag for profiler (XHProf constants). Default:false.flagMemory- enable/disable XHPROF_FLAGS_MEMORY flag for profiler (XHProf constants). Default:true.ignoredFunctions- list of functions to ignore during profiling (xhprof_enable() function). Empty by default.libPath- direct filesystem path to the directory withxhprof_libcontents.htmlUrlPath- URL path to the directory with XHProf UI contents (xhprof_html).runNamespace- predefined value of namespace for current profiler run.
All options can be changed with setters (e.g. setFlagCpu(<value>)). For more details see the source code of the class.
Manual profiling
If you disable auto start (autoStart option) or stop (autoStop option) you can place code to start/stop profiler in any place of your code and be able to see report and callgraph result via overlay or debug panel.
To manual start you need to write some kind of next code:
// create and configure instance of XHProf class \imhelle\xhprof\XHProf::getInstance()->configure(array( 'flagNoBuiltins' => true, 'flagCpu' => false, 'flagMemory' => true, 'runNamespace' => 'my-cool-namespace', 'libPath' => '/var/www/html/xhprof/xhprof_lib', 'htmlUrlPath' => 'http://test.local/xhprof/xhprof_html' )); // start profiler \imhelle\xhprof\XHProf::getInstance()->run();
To manual stop you need to write next code:
// stop profiler and get URLs to results and callgraph $urls = \imhelle\xhprof\XHProf::getInstance()->stop(); // Links: // $urls[\imhelle\xhprof\XHProf::TYPE_REPORT] // $urls[\imhelle\xhprof\XHProf::TYPE_CALLGRAPH]
Note: If you use XHProf class (with or without this extension) - all profile results can be found on XHProf UI page (it's by default by xhprof developers).
Note for PHP 7 and XHProf
If you want to use this extension with PHP 7, you can use next forked version of xhprof extension: https://github.com/rustjason/xhprof. This extension was tested on PHP 7.1.11 with extension built from provided repository.
Another better option - is to use officially ported xhprof extension by tideways.io - https://github.com/tideways/php-xhprof-extension.
imhelle/yii2-xhprof-lib 适用场景与选型建议
imhelle/yii2-xhprof-lib 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 05 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「debug」 「profiling」 「xhprof」 「yii」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 imhelle/yii2-xhprof-lib 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 imhelle/yii2-xhprof-lib 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 imhelle/yii2-xhprof-lib 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Quick profiling of your code for Laravel
Debug your SimpleBus EventBus and CommandBus
nice output for debug functions for PHP 5.3
Xhprof buggregator integration for Symfony Framework
Excimetry PHP package. Bridge between ext-eximer and open telemetry
Analysis module for finding problematical shop data.
统计信息
- 总下载量: 39
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2018-05-31