Vim XDebug調試PHP php遠端偵錯

來源:互聯網
上載者:User
xdebug 配置

xdebug 安裝

原文地址:http://xiaobin.net/201007/using-vim-and-xdebug-to-debug-php-code/

原理上,這種調試方式主要依靠Vim的外掛程式“remote PHP debugger”來實現,該外掛程式實現了一個DBGP服務端。調試的時候Xdebug將會與服務端建立一個串連進行通訊,接收服務端的調試指令並返回調試結果。

安裝和配置

XDebug

安裝:

ubuntu 下直接 apt-get install php5-xdebug 安裝

到/usr/lib/php5/20090626+lfs 即可看到xdebug.so 可拷貝到你指定的模組地址

配置:(php.ini檔案)

載入Xdebug擴充:

zend_extension=//xdebug.so #為你拷貝到的目錄

配置xdebug開啟dbgp遠端偵錯

xdebug.remote_enable=on
xdebug.remote_handler=dbgp

Vim的Debugger外掛程式

這個簡單,只需要將外掛程式下載回來,解壓放到~/.vim/plugin目錄

調試過程

用Vim開啟要調試的PHP檔案,按進入調試狀態。請移步《PHP調試指南》,上面寫的詳細一些。

注意事項

實際過程中,如果你發現安裝完成仍然無法正常的調試PHP,極可能是下面的原因造成的:

一、Xdebug載入不成功

可以通過phpinfo或者是”php -m”來確認Xdebug是不是載入成功。載入不成功的原因可能是由於PHP是”Debug Build”(可以通過phpinfo確認),那麼php.ini裡不應當用“zend_extension=//xdebug.so”,而應該用“zend_extension_debug=//xdebug.so”;

其它方面就是要注意xdebug.so路徑是否正確,Apache服務或者是fastcgi服務有沒有重啟。

phpinfo 顯示顯示如下,表示正常

二、 偵錯工作階段已經到期

XDebug 通過一個Cookie來判斷你是否進行調試對話,請注意這個Cookie的到期時間是1個小時。某天你埋頭工作的時候發現Vim + Xdebug剛剛還work,怎麼一下又不work了,那多半是由於這個會話已經到期了。

只要在URL後面帶上參數 “XDEBUG_SESSION_START=1″,偵錯工作階段就會延續1小時。

訪問路徑:

For clean URLs use: http://example.com/admin/feature?XDEBUG_SESSION_START=1

Otherwise use: http://example.com?q=admin/feature&XDEBUG_SESSION_START=1

四、更改調試等待時間 (預設5秒鐘)

編輯debuger.py

2. press and browse php file within 5 seconds. :-)
If you did setup correctly, server will make connection to vim.
[ you can change port by editing last line of debugger.vim ]

all the windows currently opened will be closed and debugger interface will be shown.

3. in debuggin mode
: resizing windows
: step into
: step over
: step out

: stop debugging

: shows all variables
: shows variable on current cursor

,e : evalute expression and display result. cursor is automatically move to watch window. type line and just press enter.

command line command)
:Bp : toggle breakpoint on current line
:Up : goto upper level of stack
:Dn : goto lower level of stack

4. press to stop debugging.
then, debugger windows will be closed and windows will be restored.
( holy :mksession feature )

參考和延伸閱讀 Using vim and xdebug DBGp for debugging Drupal (or any PHP application) remote PHP debugger

首先下載xdebug2.1.0,在官方首頁下載原始碼,下載回來的檔案名稱是:xdebug-2.1.0.tgz
xdebug的版本需與您的php版本相對應,由於偶的php是5.3.2,所以下載xdebug2.1.0

Xml代碼

cd /your/download/path tar zxvf xdebug-2.1.0.tgz cd xdebug-2.1.0

運行phpize

Xml代碼

phpize

如果沒有將phpize加入$PATH,則應該使用全路徑

這裡不需要--prefix,編譯好之後直接把modules裡的xdebug.so檔案複製走即可。

Xml代碼

./configure --enable-xdebug --with-php-config=/usr/local/php/bin/php-config

Xml代碼

make

把xdebug.so複製到了php安裝目錄,裝php的時候指定了安裝目錄,所以複製到/usr/local/php/xdebug裡。隨便你複製到哪都行,只要你清楚知道。。。需要改下面一條命令的路徑為你自己的。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.