XhProf安装教程–详细教程

  • wget
    去这里找最新的包下载,我如今最新的是xhprof-0.9.4.tgz

     

    cd /tmp
    mkdir xhprof && cd xhprof
    wget http://pecl.php.net/get/xhprof-0.9.4.tgz
    tar -xvf xhprof-0.9.4.tgz
    cd xhprof-0.9.4/extension/
    phpize

    我在进行这步的时候,提示我没有安装phpize,下一步就是安装phpize,若是已经安装了phpize,能够跳过下一步php

  • phpize
    由于phpize在php-devel包里面,因此先须要安装php-devel

     

    yum search php-devel

    若是你和我同样,找不到这个包的话,建议添加电子科技大学的源html

    cd /tmp
    wget http://mirrors.stuhome.net/files/centos_repo/6/CentOS-Base.repo
    cp CentOS-Base.repo /etc/yum.repos.d/CentOS-Base-Uestc.repo -v
    yum makecache
    yum install php-devel -y

    装好了phpize就能够进行安装了nginx

    phpize
  • 接下来是源码安装三部曲:
    whereis php-config
    /*看看你的php-config在什么路径,而后放到后面的path-to php-config,通常是/usr/bin/php-config */
    ./configure --with-php-config=<path to php-config >
    make
    make install
    mkdir -p /var/tmp/xhprof
  • 编译添加了xhprof.so文件,如今须要配置php启用这个so文件,去/etc/php.d/文件夹下面添加文件xhprof.ini
    extension=xhprof.so
    xhprof.outout_dir=/var/tmp/xhprof
    /*请肯定上面配置的/var/tmp/xhprof目录是存在的*/

    而后就是从新启动你的php,以后用命令查看sql

    php -ini | grep xhprof -i

    看看是否已经安装上了,安装好了以后,就能够开始设置监控了centos

  • 将文件拷贝到网站目录里面,而后添加监控代码到统计文件中
    mkdir -p /var/www/xhprof && cd /var/www/xhprof/
    cp -r /tmp/xhprof/xhprof-0.9.4/xhprof_html/ ./
    cp -r /tmp/xhprof/xhprof-0.9.4/examples/ ./
    cp -r /tmp/xhprof/xhprof-0.9.4/xhprof_lib/ ./
    mkdir logs

    配置nginx的虚拟主机目录,在/etc/nginx/conf.d/目录下面新建xhprof.conf
    而后修改文件内容为:ruby

    server{
      listen 80;
      server_name effect.vpsbuy.info;
      root /var/www/xhprof;
      access_log /var/www/xhprof/logs/access.log;
      error_log /var/www/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 /var/www/xhprof;
      }
      location ~ \.php$ {
          include fastcgi_params;
          fastcgi_pass php;
          fastcgi_index xhprof_html/index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }
    }

    从新启动nginx函数

    nginx -t
    nginx -s reload

    修改examples目录下面的sample.php文件,将最后一行的echo改为这样网站

    echo "---------------\n".
       "Assuming you have set up the http based UI for \n". "XHProf at some address, you can view run at \n". "http://effect.vpsbuy.info/xhprof_html/index.php?run=$run_id&source=xhprof_foo\n". "---------------\n";

    将这个http://effect.vpsbuy.info/xhprof_html/改为你本身的url路径。
    而后就是配置监控this

    $xhprof_enable = false;
    if(mt_rand(1,10)==1){ //这里设置监控的比例
      xhprof_enable();
      $xhprof_enable = true;
    }
    //这里写上你要监控的函数
    if($xhprof_enable ){
      $xhprof_data = xhprof_disable();
      //$XHPROF_ROOT = realpath(dirname(__FILE__) .'/..'); 
      $XHPROF_ROOT = /var/www/xhprof;
      include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
      include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
      // save raw data for this profiler run using default 
      // implementation of iXHProfRuns.
      $xhprof_runs = new XHProfRuns_Default();
      // save the run under a namespace "xhprof_foo" 
      $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");
    }

    如今就能够统计了,而后就是安装生成访问图像的url

    yum install graphviz

    若是你以为写得不错,请捐赠做者:

    做者:

相关文章
相关标签/搜索