Mac/インストール/xhprof
提供: 初心者エンジニアの簡易メモ
2016年12月27日 (火) 16:58時点におけるAdmin (トーク | 投稿記録)による版 (ページの作成:「==準備== brew install autoconf brew install gts brew install graphviz $ vi ~/.bash_profile export PHP_AUTOCONF="/usr/local/bin/autoconf" export PHP_AUTOHEADER="/...」)
準備
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" $ vi /usr/local/Homebrew/Library/Taps/homebrew/homebrew-php/Formula/xhprof.rb require 'formula' class Xhprof <Formula url 'https://pecl.php.net/get/xhprof-0.9.4.tgz' sha256 '002a2d4a825d16aeb3017c59f94d8c5e5d06611dd6197acd2f07fce197d3b8f8' depends_on 'pcre' def install Dir.chdir "xhprof-#{version}/extension" do system "phpize" system "./configure", "--prefix=#{prefix}" system "make" prefix.install %w(modules/xhprof.so) end Dir.chdir "xhprof-#{version}" do prefix.install %w(xhprof_html xhprof_lib) end end def caveats; <<-EOS.undent To finish installing XHProf: * Add the following lines to php.ini: [xhprof] extension="#{prefix}/xhprof.so" * Restart your webserver EOS end end
xhprofインストール
brew install xhprof
php.ini追加
$ locate php.ini $ vi /usr/local/etc/php/5.6/php.ini [xhprof] extension="/usr/local/Cellar/xhprof/0.9.4/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/xhprof/0.9.4/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/