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_BUILTINSdo not profile builtinsXHPROF_FLAGS_CPUgather CPU times for funcsXHPROF_FLAGS_MEMORYgather memory usage for funcs
Example
<?php array( "main()" => array( "wt" => 237, "ct" => 1, "cpu" => 100, ) )
wtThe execution time of the function method is time consumingctThe number of times the function was calledcpuThe CPU time consumed by the function method executionmuMemory used by function methods. The call is zend_memory_usage to get the memory usagepmuPeak 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
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 totara/xhprof 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Quick profiling of your code for Laravel
g4 application profiler package
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
Create link to static resources with cache-breaking segment based on md5 of the file
Excimetry PHP package. Bridge between ext-eximer and open telemetry
统计信息
- 总下载量: 12.3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2025-08-21
