PHP - xhprof 安装使用

PHP - xhprof 安装使用

Max.Bai

2016-09-02

0. Prepare
Get below php releate config value, like:
/usr/local/webserver/php-5.6.12/etc/php.ini 
/usr/local/webserver/php-5.6.12/bin/php-config
/usr/local/webserver/php-5.6.12/bin/phpize


Create xhprof outdir for result, default in /tmp
/data/xhprof/result


1. download xhprof
mkdir /opt/xhprof & cd /opt/xhprof
wget xxxxxxx/xhprof-0.9.4.tar.gz
tar -xzf xhprof-0.9.4.tar.gz
cd /opt/xhprof/xhprof-0.9.4/extension


2. build xhprof
phpize
./configure --with-php-config=/usr/local/webserver/php-5.6.12/bin/php-config
make and make install
after install, will show the extension path like :   
/usr/local/webserver/php-5.6.12/lib/php/extensions/no-debug-non-zts-20131226/
!!!this path will be used next step!!!

3. config php.ini
vim /YOUR_PHP_INI/php.ini
Add below config in your php.ini
[xhprof]
extension=xhprof.so
xhprof.output_dir=/data/xhprof/result
extension_dir=/usr/local/webserver/php-5.6.12/lib/php/extensions/no-debug-non-zts-20131226/

4. Restart php
/etc/init.d/php-form restart
Maybe this command is not for you, please check your restart command.


Check your xhprof is installed:
php -m | grep xhprof


or use phpinfo check.
like :
xhprof   0.9.4
cpunum   4

5. Copy xhprof to your webserver dir
Copy examples xhprof_html  xhprof_lib folder to your webserver dir

6. Config Nginx
Make sure your path is correct.
server
{
  listen 80;
  server_name xhprof.xxxx.com;
  root /data/xhprof;
  access_log /data/xhprof/logs/access.log;
  error_log /data/xhprof/logs/error.log;
  index index.php;


  location = favicon.ico {
      log_not_found off;
      access_log off;
  }    


  location = /robots.txt{
      allow all;
      log_not_found off;
      access_log off;
  }
  location / {
      root /data/xhprof;
  }
  location ~ \.php$ {
      fastcgi_pass webserver_0;
      fastcgi_index xhprof_html/index.php;
		include fastcgi.conf;


		set $script $uri;
		set $path_info  "/";
		if ($uri ~ "^(.+\.php)(/.+)") {
			set $script     $1;
			set $path_info  $2;
		}
		fastcgi_param PHP_VALUE "session.cookie_domain=xxxx.com";
		fastcgi_param PATH_INFO $path_info;
		fastcgi_param SCRIPT_FILENAME  $document_root/$script;
		fastcgi_param SCRIPT_NAME $script;
		access_log  off;
  }
}


7. Restart Nginx
Restart you rnginx


8. Now you can access xhprof page
like :
xhprof.xxxx.com/xhprof_html/index.php

9. How to use?
// start xhprof enable
if(extension_loaded('xhprof')){  
    include_once '/data/xhprof/xhprof_lib/utils/xhprof_lib.php';  
    include_once '/data/xhprof/xhprof_lib/utils/xhprof_runs.php';  
    //xhprof_enable();
    //xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);  
    //fix for nginx response with 502
    xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);  
}  


// this place is your program code


if(extension_loaded('xhprof')){  
    $ns = 'myXhprof';  
    $xhprofData = xhprof_disable();  


    $xhprofRuns = new XHProfRuns_Default();  
    $runId = $xhprofRuns->save_run($xhprofData, $ns);  
}

10. View your result
Your all results wil be list on this page.
http://xhprof.xxx.com/xhprof_html/index.php




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值