linux下vim實現php遠程調試環境搭
首先是必需組件的安裝。
有三個,vim的DBGp插件,php的xdebug擴展,Chrome瀏覽器的xdebug helper擴展。
一: vim 安裝 dbgp client 插件 下載 DBGp client
$ cd ~/.vim/ $ wget http://www.vim.org/scripts/download_script.php?src_id=7285 -O debugger.zip $ unzip debugger.zip
具體安裝方法就不講了,網上例子很多. 官方安裝說明 .
我把我的配置信息貼出來:
[Xdebug] zend_extension="/home/s/apps/php-5.2.6/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so" xdebug.profiler_enable=0 ;開啟profile xdebug.profiler_enable_trigger=1 ;使用觸發器開啟profile xdebug.profiler_output_dir="/home/s/logs/xdebugLog" xdebug.auto_trace=0 ;開啟trace xdebug.trace_enable_trigger=1 ;使用觸發器開啟trace xdebug.trace_output_dir="/home/s/logs/xdebugLog" xdebug.cli_color=1 xdebug.collect_params=2 xdebug.collect_return=on ;remote debug ;開啟遠程調試 xdebug.remote_enable=1 xdebug.remote_autostart=Off xdebug.remote_port=9000 ;遠程端口,不是你web服務的端口,如果沒有沖突,一般不用修改。
地址: https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc
如果在 chrome://apps里搜索xdebug helper搜索不到,記得把你的語言改為 English.
xdebug-helper-introduction20140226142342
第二個是domain白名單,如果不希望每個頁面都出調試的debug icon,就把開發時的域名填進來,比如localhost神馬的。其實icon很小,也不太礙事,可以不用設置。
開始使用 :
如果不要debug調試,只是需要記錄profile和trace信息,看一下性能問題,那么很簡單,直接在chrome訪問對應的url,會在url右側看到一個xdebg helper 的小icon,點擊后,選擇 profile或trace,再刷新,就可以在預先設置的目錄見到對應的文件了。
cachegrind* 是profile的文件,trace* 是trace的文件。
在windows下使用WinCacheGrind可以方便的查看profile的信息。
xdebug_helper_debug_profile_trace
xdebug_output_file_trace_profile
winCacheGrind_output
最后,是 如何開啟遠程調試 .
用vim編輯程序文件,在需要中斷的地方使用:Bp命令打上斷點。然后按F5執行監聽。
這個時候,vim會提示 waiting for a new connection on port 9000 for 5 seconds… ,所以這個時候你需要在5s內向服務端發起帶中斷的請求,在前邊的url地址,我們把xdebug helper的debug選擇上,刷新頁面,vim就會進入中斷了。右側有相關提示,我們就可以按GDB的方式逐步調試啦。如果沒有安裝xdebug helper,也無所謂,自己手動在url上拼接一個參數: &XDEBUG_SESSION_START=1 也可以開啟遠程調試的。 xdebug_remote_debug_how