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
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
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
若是你以爲寫得不錯,請捐贈做者:
做者: