zoa-chou / xhprof-collector
单个 XHProf 收集器使用 XHProf API
v1.1.2
2018-12-21 08:04 UTC
Requires
- php: >=5.6
This package is not auto-updated.
Last update: 2024-09-29 05:34:03 UTC
README
单个 XHProf 收集器使用 XHProf API。
注意,这只是一个收集器,因此您必须获取一个用于显示收集数据的 GUI,例如 xhgui。
测试的 PHP 版本
- 5.6.36
- 7.0.30
注意:如果您在 Kubernetes 下运行 PHP,则必须使用仅支持 PHP >= 7.0 的 tideways_xhprof 扩展,以避免在 hp_execute_internal 中 XHProf 崩溃。
需求
XHProf 扩展(任选其一)
- uprofiler
- tideways
- tideways_xhprof(推荐)
- xhprof
mongo 扩展(任选其一)
Symfony 集成示例
包含(任选其一)
- Composer(推荐)
{
"require" : {
"zoa-chou/xhprof-collector": "*",
}
}
- 单个文件
- 将 xhprof-collector/src/collector.php 复制到您的路径
- 首先在项目中引入收集器,例如
<?php require_once '/path/to/your/collector.php';
- Nginx 配置
- 将 xhprof-collector/src/collector.php 复制到您的路径
- 在 server 块内部添加 fastcgi_param 到您的 nginx 配置中,例如
location ~ .*\.php?$ {
fastcgi_param PHP_VALUE "auto_prepend_file=/path/to/your/collector.php";
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
注意:一旦您访问了配置了收集器的服务器主机,nginx 就会始终向 php-fpm 发送 fastcgi_param,即使您访问其他未配置的服务器。
- 追加 php.ini
- 将 xhprof-collector/src/collector.php 复制到您的路径
- 在您的 php.ini 中添加 auto_prepend_file,例如
auto_prepend_file=/path/to/your/collector.php
配置环境变量
- XHGUI_ENABLE_PROB —— 请求时启动收集器的概率。有效值介于 0(关闭)和 100(全部开启)之间,默认为 0。
- XHGUI_MONGO_URI —— mongodb uri,例如:
mongodb://username:password@ip:host,ip2:host2/dbname?connectTimeoutMS=200
- XHGUI_ENABLE_CLI —— 当 PHP 以 CLI 模式运行时启用收集器。有效值是 0(关闭)和 1(开启),默认为 0。
- XHGUI_SINGLE_CONTROL —— 启用使用 http 标头 XHGUI-ENABLE-PROB(类似于 XHGUI_ENABLE_PROB,例如:'XHGUI-ENABLE-PROB: 100')来控制启动收集器的概率,这将覆盖 XHGUI_ENABLE_PROB。有效值是 0(关闭)和 1(开启),默认为 0。