-
PHP扩展:xhprof
-
安装gd、graphviz、fontconfig
如,以centos系统为例,可以使用yum安装方式
# yum install -y gd gd-devel fontconfig fontconfig-devel graphviz
composer require myziyue/xhprof
<?php
include './vendor/autoload.php';
function foo() {
for ($idx = 0; $idx < 5; $idx++) {
bar($idx);
$x = strlen("abc");
}
}
\myziyue\xhprof\ZyXhprof::startProfiling(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);
// run program
foo();
\myziyue\xhprof\ZyXhprof::stopProfiling('demo');
- 1、nginx配置文件增加如下代码:
fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/vendor/myziyue/xhprof/ZyPreInject.php";
fastcgi_param PHP_VALUE "auto_append_file=/var/www/vendor/myziyue/xhprof/ZyEndInject.php";
- 2、php.ini方式:
auto_prepend_file=/var/www/vendor/myziyue/xhprof/ZyPreInject.php;
auto_append_file=/var/www/vendor/myziyue/xhprof/ZyEndInject.php;
- 首先,启动服务
./vendor/bin/zyxpf
- 然后,通过浏览器,查看分析结果
http://localhost:1105/