承接 stevad/yii-xhprof 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

stevad/yii-xhprof

最新稳定版本:v0.1.1

Composer 安装命令:

composer require stevad/yii-xhprof

包简介

Yii extension to profile application with Facebook XHProf

README 文档

README

Warning

This repository is not maintained anymore!

Simple extension to use XHProf with Yii Framework 1.x.

Can work together with yii2-debug extension (bundled with debug panel for it).

By default profile starts on onBeginRequest event and stops on onEndRequest event. You can change this behavior and manually start and stop profiler.

For license information check the LICENSE file.

Tested on Yii Framework v1.1.16.

Installation

This extension is available at packagist.org and can be installed via composer by following command:

composer require --dev stevad/yii-xhprof.

If you want to install this extension manually - copy sources to /protected/extensions directory.

Minimal configuration to enable profiler:

return array(
    'preload' => array(
        'xhprof'
    ),
    'components' => array(
        'xhprof' => array(
            'class' => 'ext.yii-xhprof.XHProfComponent', // if you install to protected/extensions
            'libPath' => '/full/path/to/xhprof_lib',
            'htmlReportBaseUrl' => 'http://url.path.to/xhprof_html',
        ),
    ),
);

If you want to add bundled debug panel to yii2-debug extension - update configuration next way:

return array(
    'components' => array(
        'debug' => array(
            // ... other debug config options ...
            'panels' => array(
                'xhprof' => array(
                    'class' => 'ext.yii-xhprof.XHProfPanel' // if you install to protected/extensions
                )
            )
        ),
    ),
);

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.
  • reportPathAlias - path alias to the directory to store JSON file with previous profiler runs. Default: application.runtime.xhprof
  • maxReportsCount - number of profile reports to store. Default: 25.
  • manualStart - flag to manually start profiler from desired place. Default: false.
  • manualStop - flag to manually stop profiler from desired place. Default: false.
  • forceStop - flag to force stop profiler on onEndRequest event if manualStop is enabled and profiler 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 be true if you are using bundled panel for yii2-debug extension. Default: true.
  • libPathAlias - path alias to the directory with xhprof_lib contents if it is placed somewhere in your Yii project. This option has more priority than libPath.
  • libPath - direct filesystem path to the directory with xhprof_lib contents.
  • 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.
  • blacklistedRoutes - list of routes which profiler should ignore. Allowed wildcard * which means 'any alphanumeric value and one of this: /, ., _, -. Default: array('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.
  • libPath - direct filesystem path to the directory with xhprof_lib contents.
  • htmlUrlPath - URL path to the directory with XHProf UI contents (xhprof_html).
  • runId - predefined value of identifier for current profiler run.
  • 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 enable manual start (manualStart option) or stop (manualStop option) you can place code to start/stop profiler in any place of your code and be able to see report and callgraph result.

To manual start you need to write some kind of next code:

// create and configure instance of XHProf class
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
XHProf::getInstance()->run();

To manual stop you need to write next code:

// stop profiler
XHProf::getInstance()->stop();

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).

Author

Copyright (c) 2015 by Stevad.

stevad/yii-xhprof 适用场景与选型建议

stevad/yii-xhprof 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.42k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 10 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「debug」 「extension」 「profiling」 「xhprof」 「yii」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 stevad/yii-xhprof 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 stevad/yii-xhprof 我们能提供哪些服务?
定制开发 / 二次开发

基于 stevad/yii-xhprof 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 25
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-10-16