phpstorm + xdebug 远程断点调试
CentOS(Linux)下安裝Xdebug
Xdebug是一個(gè)開放源代碼的PHP程序調(diào)試器(即一個(gè)Debug工具),可以用來跟蹤,調(diào)試和分析PHP程序的運(yùn)行狀況,本文主要記錄一下在centos(linux)下xdebug的安裝和配置方法。
首先讓php錯(cuò)誤顯示,只需要修改php.ini當(dāng)中的2條指令,把 displayerrors和htmlerrors都設(shè)置為On,如下所示:
html_errors = On
display_errors = On
當(dāng)然如果你要需要查看更多信息,比如說打印調(diào)用棧,哪就需要安裝xdebug,這個(gè)對(duì)于比較復(fù)雜的代碼系統(tǒng)特別有幫助。
xdebug是php的一個(gè)module,需要編譯安裝,我用lnmp安裝的php,php被默認(rèn)安裝到/usr/local/php,然后做一個(gè)硬鏈接到/usr/bin。
(1)下載xdebug
xdebug 下載地址頁:https://xdebug.org/download.php
wget https://xdebug.org/files/xdebug-2.4.0rc4.tgz
注意:xdebug的版本需與您的php版本相對(duì)應(yīng),由于我的php是5.6,所以這里下載是:xdebug2.4
(2)編譯xdebug
然后開始編譯
tar xzf xdebug-2.4.0rc4.tgz
cd xdebug-2.4.0RC4/
phpize
注意這里如果你的phpize沒有加入到環(huán)境變量的話,需要帶該文件的全路徑
./configure --enable-xdebug --with-php-config=/usr/local/php/bin/php-config
這里的php-config參數(shù)要改為你實(shí)際的php-config地址額,不知道的話自己搜吧。
make
make test
make install
(4)配置php.ini
編譯完成之后可以去php的安裝目錄通過find搜索一下是否生成了xdebug.so文件。如果生成成功,就可以直接配置php.ini文件了。具體配置代碼如下:
[Xdebug]??
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"??
xdebug.profiler_enable=on???
xdebug.trace_output_dir="/usr/local/php5/xdebug/"??
xdebug.profiler_output_dir="/usr/local/php5/xdebug/"??
xdebug.remote_enable=on?????????????
xdebug.remote_handler=dbgp????????????
;xdebug.remote_host=localhost??
xdebug.remote_port=9999?
重啟php-fpm,可以通過phpinfo()檢查你的xdebug是否安裝成功,也可以隨便寫段錯(cuò)誤的php代碼,刷新瀏覽器,就能看到錯(cuò)誤提示。
xdebug配置
1.在php.ini配置文件中添加如下內(nèi)容
zend_extension="/wherever/you/put/it/xdebug.so"
2.如果是php5.3之前版本線程安全,添加如下內(nèi)容代替上面1的內(nèi)容
zend_extension_ts="/wherever/you/put/it/xdebug.so"
3.自從php5.3之后zend_extension_ts, zend_extension_debug不再使用
4.xdebug的一些其他配置
;顯示錯(cuò)誤信息 xdebug.default_enable?=?1;函數(shù)調(diào)試 xdebug.auto_trace=on xdebug.trace_output_dir xdebug.trace_output_name ;Type:?string,?Default?value:?trace.%c xdebug.collect_params?=?1|3|4?(參數(shù)長度,參數(shù)值,參數(shù)=值) xdebug.show_mem_delta=1?顯示內(nèi)存 xdebug.collect_return=1?顯示返回值 xdebug.trace_options?=1?追加日志 xdebug.collect_params=1xdebug.collect_vars?=?1;開啟性能分析 xdebug.profiler_enable=1;性能分析日志保存目錄 xdebug.profiler_output_dir?=?/data/logs/xdebug/ ;性能分析日志文件名稱 xdebug.profiler_output_name?=?cachegrind.out.log;默認(rèn)是如下格式,t時(shí)間,p進(jìn)程id ;xdebug.profiler_output_name?=?cachegrind.out.%t.%p;代碼覆蓋率 xdebug.coverage_enable?=?1;以下是遠(yuǎn)程調(diào)試配置 xdebug.remote_host=?127.0.0.1xdebug.remote_connect_back?=?1xdebug.remote_port?=?9000xdebug.remote_log="/data/logs/xdebug/xdebug.log"4.重啟php使配置生效
性能分析日志工具
1.linux平臺(tái)
工具KCacheGrind (Linux, KDE)?https://kcachegrind.github.io/
2.win平臺(tái)查看工具WinCacheGrind
相關(guān)網(wǎng)址
http://ceefour.github.io/wincachegrind/https://sourceforge.net/projects/wincachegrind/https://github.com/ceefour/wincachegrind/releases/tag/1.1列名稱含義
Self - Shows the execution time of the code in the current block
Cum. - Shows the total exuction time of functions that the current function (Self) calls
Avg vs. Total: Average is average time per call, Total is the total time spend in all calls.
3.Web方式查看webgrind
https://github.com/jokkedk/webgrind
PHPSTORM 配置:
1.file->setings->php|Debug右側(cè)。xdebug的那一塊。 設(shè)置Debug port:9900(這里設(shè)置 的是,xdebug 吐出的debug信息,通過本機(jī)的什么端口傳輸。)
2.file->setings->php|Servers? 右側(cè)。? host: 你的web服務(wù)器的域名或ip ,端口,? 下面的 use path mapping? 意的是,你的項(xiàng)目的目錄,對(duì)應(yīng)服務(wù)器上的,什么目錄??? 這里一定要設(shè)置哦! 不然,會(huì)發(fā)生找不到文件而出錯(cuò),導(dǎo)至調(diào)試終止。
3.Run->Edit Configurations-> 增加一個(gè) PHP WEB APPlication 的調(diào)試點(diǎn)。? 右側(cè): server 選擇你上面建立的server.? starturl 設(shè)置你的入口文件。
至此,配置完畢!
這樣的請(qǐng)求,可以注冊一個(gè)調(diào)試客戶端哦!
http://www.aihuxi.com/****.php?XDEBUG_SESSION_START=19192
點(diǎn)擊,小蟲子圖標(biāo),即可,開始調(diào)試!?
本文轉(zhuǎn)自 2012hjtwyf 51CTO博客,原文鏈接:http://blog.51cto.com/hujiangtao/1920665,如需轉(zhuǎn)載請(qǐng)自行聯(lián)系原作者
總結(jié)
以上是生活随笔為你收集整理的phpstorm + xdebug 远程断点调试的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: office频繁显示停止工作
- 下一篇: 工作问题之:redis 保存快照问题