xhgui基于xhprof,图形化显示结果。简单更直观。使用tideways+xhgui组合的原因是我的PHP版本是7,xhprof不支持,(虽然安装了一个支持php7的xhprof,但是没有资料,估计是不兼容xhgui。)前提是我的PHP版本是PHP7:MongoDB的版本是V3.6.2:安装步骤1、安装mongodb(mac下自行google或baidu安装mongodb)brewinstallmongodb2。安装php的mongodbextensionbrewinstallphp70-mongo查看是否安装成功(记得重启php-fpm)3.安装php的tidewaysextensionbrewinstallphp70-tidewayscd/usr/local/etc/php/7.0/conf。dvimext-tideways_xhprof.ini添加内容(这是编译成功后的路径)[tideways_xhprof]extension="/usr/local/Cellar/php70/7.0.14_7/lib/php/extensions/no-debug-non-zts-20151012/tideways_xhprof.so";不需要自动加载,在程序中控制tideways.auto_prepend_library=0即可;frequency设置为100,可以在调用程序的时候改tideways.sample_rate=100,检查是否安装成功(记得重启php-fpm)4.安装xhguicd/Users/birjemin/Developer/Phpgitclonehttps://github.com/laynefyc/xhgui-branch.git//这里我把xhgui-branch目录重命名为xhprof_guicdxhprof_gui/extensionphpinstall.phpconfigurexhgui(extension,profiler.enable,db.host,db.dbParameters)cd/Users/birjemin/Developer/Php/xhprof_gui/configcpconfig.default.phpconfig.phpvimconfig.php恭喜安装成功!使用step1.mongodb需要新建对应的db(配置在上面confi.php第四点)createanewindexoptimizationquery$mongo>usexhprof>db.results.ensureIndex({'meta.SERVER.REQUEST_TIME':-1})>db.results.ensureIndex({'profile.main().wt':-1})>db.results.ensureIndex({'profile.main().mu':-1})>db.results.ensureIndex({'profile.main().cpu':-1})>db.results.ensureIndex({'meta.url':1})2.被监控的网站nginx配置加上fastcgi_paramTIDEWAYS_SAMPLERATE"25";3、可以在需要监控的界面中的代码片段前引入header.phpinclude"/Users/birjemin/Developer/Php/xhprof_gui/external/header.php";4.克隆的xprof_gui配置虚拟主机,和你的项目一样,所以把xprof当作一个项目,配置成浏览器可以访问比如我的配置:host:127.0.0.1local.xhprof_gui.comnginxserverconfserver{listen80;server_namelocal.xhprof-gui.com;#root指令应该是全局root/Users/birjemin/Developer/Php/xhprof_gui/webroot;索引index.php;location/{try_files$uri$uri//index.php?$args;}location~\.php${try_files$uri=404;包括fastcgi_params;fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;}}5.重启nginx,用浏览器访问local.xhprof-gui.com看能不能访问(没有目录??难道用浏览器不能访问目录??权限没开。。配置一下自己)6.在postman或者浏览器中访问界面,翻来翻去,然后就可以去http://local.xhprof-gui.com/查看了。(我不会切图。。)遇到的问题1.安装后,运行时数据为空。估计是我安装的xhprof虽然支持PHP7,但是不兼容xhgui。修改config.php中的extension参数为tideways_xhprof报错而不是xhprof2.mongoDb是bug(issue),请按照此方法修改对应文件。3.为什么不在nginx中配置fastcgi_paramPHP_VALUE"auto_prepend_file=/Users/birjemin/Developer/Php/xhprof_gui/external/header.php";但包括“/Users/birjemin/Developer/Php/xhprof_gui/external/header.php”;因为我是在本地调试,重点分析某个接口,而不是观察线上的正式环境。还有这个原因问题注意重启php-fpm(看个人重启方式,我的重启方式是这样的)cd/usr/local/etc/php/7.0/sudokillallphp-fpmsudo/usr/local/Cellar/php70/7.0.14_7/sbin/php-fpm-D参考https://github.com/laynefyc/xhgui-branch/issues/10https://segmentfault.com/a/1190000007580819http://blog.it2048.cn/article_tideways-xhgui.htmlhttps://github.com/laynefyc/xhgui-branch/issues/13
