xhorof php性能分析工具
原创文章,转载请注明出处:https://reatang.com/?id=34
工具:
php >= 7.0: https://github.com/longxinH/xhprof
php < 7.0 : https://github.com/phacility/xhprof
1、创建文件 php71-xhprof.rb
$>touch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-php/Formula/php71-xhprof.rb
2、选择你喜欢的编辑器打开上面创建的文件,然后将如下内容复制进去并保存
# file /usr/local/Homebrew/Library/Taps/homebrew/homebrew-php/Formula/php71-xhprof.rb require File.expand_path("../../Abstract/abstract-php-extension", __FILE__) class Php71Xhprof < AbstractPhp71Extension init desc "XHProf is a function-level hierarchical profiler for PHP and has a simple HTML based user interface." homepage "https://github.com/longxinH/xhprof" url "https://github.com/longxinH/xhprof/archive/v1.2.tar.gz" sha256 "a0026e6047512ee289e59b188a40a6517aace40d4c65f7f23714aa4f0458089c" head "https://github.com/longxinH/xhprof.git" depends_on "pcre" def install Dir.chdir "extension" do ENV.universal_binary if build.universal? safe_phpize system "./configure", "--prefix=#{prefix}", phpconfig system "make" prefix.install "modules/xhprof.so" end prefix.install %w[xhprof_html xhprof_lib] write_config_file if build.with? "config-file" end end
3、使用命令开始安装
$>brew install homebrew/php/php71-xhprof
4、编辑配置文件
; file /usr/local/etc/php/7.1/conf.d/ext-xhprof.ini [xhprof] extension="/usr/local/opt/php71-xhprof/xhprof.so" ; 我的配置是设置为我的家目录 xhprof.output_dir="/Users/reatang/.xhprof"
5、将xhprof的web页面添加到nginx配置中(如:创建xhprof.conf),并重启nginx
# file /usr/local/etc/nginx/servers/xhprof.conf server { listen 80; server_name xhprof.local; # 需要填入 /etc/hosts index index.php index.html index.htm; charset utf-8; root "/usr/local/Cellar/php71-xhprof/1.2/xhprof_html/"; location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } location ~ /\.ht { deny all; } location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php { fastcgi_pass 127.0.0.1:9000; # 如果用的是Laravel的 valet,则写:unix:/Users/reatang/.valet/valet.sock try_files $uri /index.php = 404; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
6、重启 nginx,重启php-fpm
7、可以看一看 https://github.com/longxinH/xhprof 的示例代码进行使用操作
注意:
可能需要安装图片工具:
$>brew install graphviz
p.s:做了一个laravel5.5的测试,无法直视
确实是一个hello world 12000+的调用