PHP性能监测的工具 – XHProf

一、安装配置
xhprof的安装配置很简单,我们首先在 PECL 的网站上下载 源码包 然后执行安装过程 http://pecl.php.net/package/xhprof

% cd /extension/
% phpize
% ./configure –with-php-config= % make
% make install
% make test
php.ini file: You can update your php.ini file to automatically load your extension. Add the following to your php.ini file.
[xhprof]
extension=xhprof.so
;
; directory used by default implementation of the iXHProfRuns
; interface (namely, the XHProfRuns_Default class) for storing
; XHProf runs.
;
xhprof.output_dir=

 

二、测试示例

<?php

$xhprof_root = “/home/test/install/xhprof”;//这里填写的就是你的xhprof的路径
include_once $xhprof_root.”/xhprof_lib/utils/xhprof_lib.php”;
include_once $xhprof_root.”/xhprof_lib/utils/xhprof_runs.php”;

class XhprofTest
{
public static function init()
{
xhprof_enable();
}
public static function run($name)
{
$data = xhprof_disable();
$xhprof_runs = new XHprofRuns_Default();
$run_id = $xhprof_runs->save_run($data, $name);
$hostname = php_uname(‘n’);
var_dump(“http://{$hostname}:9008/xhprof/index.php?run=$run_id&source=$name”);
}
}

三、配置web目录

将安装的xhprof_html 目录配置到web下,形成web可访问目录

server {
listen 80;
server_name xhprof.test.com;

root /home/test/install/xhprof/xhprof_html;
index index.html index.php;

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

You May Also Like

About the Author: daidai5771

发表评论

电子邮件地址不会被公开。 必填项已用*标注