totara/xhprof 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

totara/xhprof

Composer 安装命令:

composer require totara/xhprof

包简介

Fork of XHProf for Totara

README 文档

README

This is a fork specifically for Totara projects.

XHProf is a function-level hierarchical profiler for PHP and has a simple HTML based navigational interface. The raw data collection component is implemented in C (as a PHP extension). The reporting/UI layer is all in PHP. It is capable of reporting function-level inclusive and exclusive wall times, memory usage, CPU times and number of calls for each function. Additionally, it supports ability to compare two runs (hierarchical DIFF reports), or aggregate results from multiple runs.

This version supports PHP8 and supports Totara 20 onwards only.

PHP Version

  • 8.2

Installation

git clone https://github.com/totara/xhprof.git ./xhprof
cd xhprof/extension/
/path/to/php7/bin/phpize
./configure --with-php-config=/path/to/php7/bin/php-config
make && sudo make install

configuration add to your php.ini

[xhprof]
extension = xhprof.so
xhprof.output_dir = /tmp/xhprof

php.ini configuration

    Options       Defaults Version Explain
xhprof.output_dir   "" All Output directory
xhprof.sampling_interval   100000 >= v2.* Sampling interval to be used by the sampling profiler, in microseconds
xhprof.sampling_depth   INT_MAX >= v2.* Depth to trace call-chain by the sampling profiler
xhprof.collect_additional_info   0 >= v2.1 Collect mysql_query, curl_exec internal info. The default is 0. Open value is 1

Turn on extra collection

php.ini adds xhprof.collect_additional_info

xhprof.collect_additional_info = 1

Options

xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);
  • XHPROF_FLAGS_NO_BUILTINS do not profile builtins
  • XHPROF_FLAGS_CPU gather CPU times for funcs
  • XHPROF_FLAGS_MEMORY gather memory usage for funcs

Example

<?php

array(
    "main()" => array(
        "wt" => 237,
        "ct" => 1,
        "cpu" => 100,
    )
)
  • wt The execution time of the function method is time consuming
  • ct The number of times the function was called
  • cpu The CPU time consumed by the function method execution
  • mu Memory used by function methods. The call is zend_memory_usage to get the memory usage
  • pmu Peak memory used by the function method. The call is zend_memory_peak_usage to get the memory

PDO::exec

PDO::query

mysqli_query

$mysqli = new mysqli("localhost", "my_user", "my_password", "user");
$result = $mysqli->query("SELECT * FROM user LIMIT 10");
Output data
mysqli::query#SELECT * FROM user LIMIT 10

PDO::prepare

Convert preprocessing placeholders for actual parameters, more intuitive analytic performance (does not change the zend execution process)

$_sth = $db->prepare("SELECT * FROM user where userid = :id and username = :name");
$_sth->execute([':id' => '1', ':name' => 'admin']);
$data1 = $_sth->fetch();

$_sth = $db->prepare("SELECT * FROM user where userid = ?");
$_sth->execute([1]);
$data2 = $_sth->fetch();
Output data
PDOStatement::execute#SELECT * FROM user where userid = 1 and username = admin
PDOStatement::execute#SELECT * FROM user where userid = 1

Curl

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.baidu.com");
$output = curl_exec($ch);
curl_close($ch);
Output data
curl_exec#http://www.baidu.com

PECL Repository

pecl

totara/xhprof 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 906
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2025-08-21