項目即將上線,想經過一些工具來分析代碼的穩定性和效率,想起在上個團隊時使用過的xhprof擴展;由於換了新電腦,因此須要從新編譯此擴展,現將安裝與實際排查過程完整記錄下來,方便本身回顧和幫助更多的讀者。php
xhprof擴展PHP並不自帶,須要筆者去單獨安裝它,安裝以後才能使用,筆者這裏採用源碼安裝方式,安裝過程以下git
xhprof在PHP的PECL官方上面已經比較老了,筆者的PHP版本爲PHP7.1所以,須要在GitHub上下載xhprof上比較新的源碼,參考命令以下github
git clone https://github.com/longxinH/xhprof
進入編譯的文件夾,參考命令app
cd xhprof/extension/
如今筆者須要編譯一下源碼,在編譯以前可使用phpze來探測PHP的環境,參考命令以下:工具
phpize
返回結果以下測試
Configuring for: PHP Api Version: 20160303 Zend Module Api No: 20160303 Zend Extension Api No: 320160303
生成 Makefile,爲下一步的編譯作準備ui
./configure
返回結果以下spa
creating libtool appending configuration tag "CXX" to libtool configure: creating ./config.status config.status: creating config.h config.status: config.h is unchanged
開始編譯,並進行安裝code
make && make install
返回結果以下get
Build complete. Don't forget to run 'make test'. Installing shared extensions: /usr/local/Cellar/php@7.1/7.1.19/pecl/20160303/
從返回信息中能夠看到已經安裝完成,並顯示了擴展文件存放的位置
在編譯安裝源碼以後,筆者還須要對PHP的配置文件夾以及xhprof的進行一些簡單的配置,操做過程以下所示