準備
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;
root /usr/local/Cellar/php56-xhprof/254eb24/xhprof_html;
index index.php index.html;
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
プロファイルコード追加
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/