facebook twitter hatena line google mixi email

Mac/インストール/xhprof

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

準備

brew install autoconf
brew install gts
brew install graphviz
$ vi ~/.bash_profile
export PHP_AUTOCONF="/usr/local/bin/autoconf"
export PHP_AUTOHEADER="/usr/local/bin/autoheader"

xhprofインストール

$ brew install php56-xhprof

php.ini追加

$ locate php.ini
$ vi /usr/local/etc/php/5.6/php.ini
[xhprof]
extension="/usr/local/Cellar/php56-xhprof/254eb24/xhprof.so"
xhprof.output_dir="/tmp"

nginx設定

$ vi /usr/local/etc/nginx/servers/xhprof.conf
server {
  listen       80;
  server_name  xhprof.local;
  root /usr/local/Cellar/php56-xhprof/254eb24/xhprof_html;
  index  index.php index.html;
  location ~* \.(jpg|jpeg|gif|png|swf|css|js|inc|ico|pdf|flv|gz|woff|html|htm|txt|xml)$ {
      root /usr/local/Cellar/php56-xhprof/254eb24/xhprof_html;
      index   index.html;
      ssi     on;
      access_log off;
      break;
  }
  location / {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
  }
}

hosts設定

$ sudo vi /etc/hosts
127.0.0.1 xhprof.local

プロファイルコード追加

xhprof_enable();
// ここに解析処理
$xhprof_data = xhprof_disable();
$XHPROF_ROOT = "/usr/local/Cellar/xhprof/0.9.4";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$source = 'source_name';
$run_id = $xhprof_runs->save_run($xhprof_data, $source);

httpアクセス

処理を流した後、ttp://xhprofにアクセス

参考

http://sawara.me/php/2558/