facebook twitter hatena line 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="/...」)
 
 
(同じ利用者による、間の3版が非表示)
行8: 行8:
 
  export PHP_AUTOHEADER="/usr/local/bin/autoheader"
 
  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
 
 
参考:
 
https://github.com/msonnabaum/homebrew/blob/92f3795d2dcd5e74fb6f47a30b4f6293ee31fada/Library/Formula/xhprof.rb
 
 
 
==xhprofインストール==
 
==xhprofインストール==
brew install xhprof
+
$ brew install php56-xhprof
  
 
==php.ini追加==
 
==php.ini追加==
行45: 行15:
 
  $ vi /usr/local/etc/php/5.6/php.ini
 
  $ vi /usr/local/etc/php/5.6/php.ini
 
  [xhprof]
 
  [xhprof]
  extension="/usr/local/Cellar/xhprof/0.9.4/xhprof.so"
+
  extension="/usr/local/Cellar/php56-xhprof/254eb24/xhprof.so"
 
  xhprof.output_dir="/tmp"
 
  xhprof.output_dir="/tmp"
  
行52: 行22:
 
  server {
 
  server {
 
   listen      80;
 
   listen      80;
   server_name  xhprof;
+
   server_name  xhprof.local;
   root /usr/local/Cellar/xhprof/0.9.4/xhprof_html;
+
   root /usr/local/Cellar/php56-xhprof/254eb24/xhprof_html;
 
   index  index.php index.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 / {
 
   location / {
 
     fastcgi_pass  127.0.0.1:9000;
 
     fastcgi_pass  127.0.0.1:9000;
行65: 行42:
 
==hosts設定==
 
==hosts設定==
 
  $ sudo vi /etc/hosts
 
  $ sudo vi /etc/hosts
  127.0.0.1 xhprof
+
  127.0.0.1 xhprof.local
  
 
==プロファイルコード追加==
 
==プロファイルコード追加==

2016年12月27日 (火) 18:42時点における最新版

準備

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/