安裝mongodb
需要下載3.2版本,其他版本xhgui會有兼容性bug。
下載地址:windows版本mongodb_3.2
- 啓動mongodb
./mongod.exe --dbpath D:/AppData/mongodb/data/db
- 連接mongodb,並創建db,然後添加索引如下
./mongo.exe
> use xhprof
> 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})
> db.results.ensureIndex({'meta.simple_url':1})
下載xhprof的php擴展與mongodb的php擴展
因爲官方的xhprof不支持php7,所以採用tideways版本的xhprof
下載地址:windows版tideways_xhprof
源碼地址:github地址
下載地址:windows版mongodb
下載xhgui
該項目用來展示性能分析數據所用
下載地址:git地址
- composer install更新vendor包
- 修改文件header.php,所有的tideways都替換爲tideways_xhprof,包括擴展名與函數名,以及常量,例如TIDEWAYS_FLAGS_CPU替換爲TIDEWAYS_XHPROF_FLAGS_CPU等等,另外要刪除NO_SPAN這個常量。
- config.php文件中的profiler.enable是用來控制記錄頻率的,可以設置爲100%,表示100%記錄日誌。
- xhgui在php7下會對加密報錯,所有報錯的函數名前面都要加上@符號即可。
- 在項目中將header.php文件require進去即可記錄日誌。
- xhgui的nignx配置如下:
server {
listen 80;
root D:/www/xhgui/webroot;
server_name myxhgui.com;
index index.html index.php;
location / {
try_files $uri $uri/ /index.php?$uri&$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}