調試技術是我們程式設計中不可或缺的重要部分,而除錯器是每個IDE環境都必備的元件。既然如此,Zend Studio的整合環境擁有一個調試器也就是理所當然的事情了,但是,該調試器在配置使用起來,其顯示出來的強勁功能一定會讓你驚嘆不已!
事實上,Zend Studio(後面簡稱ZDE)的偵錯功能分為內部偵錯和遠端偵錯。內部調試是用ZDE內建的PHP(有4、5兩個版本)進行的程式碼初步調試,我們把重點放在遠端調試上,因為它可以完全模擬一個真實的運行環境。
遠端調試需要伺服器端的組件支持,我們今天的內容就是怎麼來安裝這個伺服器端調試環境,用到的調試組件是Zend Debugger,它是輕便而且夠用的,在撰寫本文時,其最新版本為5.2.14,與網路上廣為流傳的5.2.10版略有更新。我的伺服器是windows下的apache,所以我下載了windows版的Zend Debugger,下來的壓縮包大約2.1M,有個readme.txt,我覺得有必要看哈子:
<ol class="dp-xml"> <li class="alt"><span><span>Zend Debugger installation instructions </span></span></li> <li><span>————————————— </span></li> <li class="alt"><span>1. Locate ZendDebugger.so or ZendDebugger.dll file that is compiled for the correct version of PHP </span></li> <li><span>(4.3.x, 4.4.x, 5.0.x, 5.1.x, 5.2.x) in theappropriate directory. </span></li> <li class="alt"><span> </span></li> <li><span>2. Add the following line to the php.ini file: </span></li> <li class="alt"> <span>Linux and Mac OS X: </span><span class="attribute">zend_extension</span><span>=/full/path/to/ZendDebugger.so </span> </li> <li> <span>Windows: </span><span class="attribute">zend_extension_ts</span><span>=/full/path/to/ZendDebugger.dll </span> </li> <li class="alt"> <span>Windows non-tread safe: </span><span class="attribute">zend_extension</span><span>=/full/path/to/ZendDebugger.dll </span> </li> <li><span>(*) the windows non-thread safe is used only with Zend Core 2.0 </span></li> <li class="alt"><span> </span></li> <li><span>3. Add the following lines to the php.ini file: </span></li> <li class="alt"> <span class="attribute">zend_debugger.allow_hosts</span><span>=</span><span class="tag"><</span><span class="tag-name">ip_addresses</span><span class="tag">></span><span> </span> </li> <li> <span class="attribute">zend_debugger.expose_remotely</span><span>=</span><span class="attribute-value">always</span><span> </span> </li> <li class="alt"><span> </span></li> <li><span>4. Place dummy.php file in the document root directory. </span></li> <li class="alt"><span> </span></li> <li><span>5. Restart web server. </span></li> <li> </li> </ol>
這裡已經非常詳細的講了安裝方法了,那我就以我晦澀的語言再描述一遍吧,以下是壓縮包內所有文件的列表:
<ol class="dp-xml"> <li class="alt"><span><span>ZendDebugger-5.2.14RC9-cygwin_nt-i386md5 </span></span></li> <li><span>ZendDebugger-5.2.14RC9-cygwin_nt-i386Inventory.xml </span></li> <li class="alt"><span>ZendDebugger-5.2.14RC9-cygwin_nt-i3864_3_x_comp </span></li> <li><span>ZendDebugger-5.2.14RC9-cygwin_nt-i3864_3_x_compZendDebugger.dll </span></li> <li class="alt"><span>ZendDebugger-5.2.14RC9-cygwin_nt-i3864_4_x_comp </span></li> <li><span>ZendDebugger-5.2.14RC9-cygwin_nt-i3864_4_x_compZendDebugger.dll </span></li> <li class="alt"><span>ZendDebugger-5.2.14RC9-cygwin_nt-i3865_0_x_comp </span></li> <li><span>ZendDebugger-5.2.14RC9-cygwin_nt-i3865_0_x_compZendDebugger.dll </span></li> <li class="alt"><span>ZendDebugger-5.2.14RC9-cygwin_nt-i3865_1_x_comp </span></li> <li><span>ZendDebugger-5.2.14RC9-cygwin_nt-i3865_1_x_compZendDebugger.dll </span></li> <li class="alt"><span>ZendDebugger-5.2.14RC9-cygwin_nt-i3865_2_x_comp </span></li> <li><span>ZendDebugger-5.2.14RC9-cygwin_nt-i3865_2_x_compZendDebugger.dll </span></li> <li class="alt"><span>ZendDebugger-5.2.14RC9-cygwin_nt-i3865_2_x_nts_comp </span></li> <li><span>ZendDebugger-5.2.14RC9-cygwin_nt-i3865_2_x_nts_compZendDebugger.dll </span></li> <li class="alt"><span>ZendDebugger-5.2.14RC9-cygwin_nt-i386dummy.php </span></li> <li><span>ZendDebugger-5.2.14RC9-cygwin_nt-i386README.txt </span></li> <li> </li> </ol>
解壓出合適的也就是和你目前php的版本對應的Zend Debugger版本,我的php版本是5.2.5,所以我就把5_2_x_comp給拖出來了(至於5_2_x_nts_comp指的是non-tread safe,沒有明白具體用途,也就不妄用了),我將5_2_x_compZendDebugger.dll移動到D:myserverZendDebugger5_2_xZendDebugger.dll,將壓縮包中的dummy.php解壓到web根目錄,我這裡的apache的DocumentRoot設置在D:/myserver/wwwroot,就拷貝dummy. php到D:myserverwwwroot,然後修改php.ini,加入了這些內容:
<ol class="dp-xml"> <li class="alt"><span><span class="attribute">zend_extension_ts</span><span>=</span><span class="attribute-value">D</span><span>:/myserver/ZendDebugger/5_2_x/ZendDebugger.dll </span></span></li> <li> <span class="attribute">zend_debugger.allow_hosts</span><span>=</span><span class="attribute-value">127</span><span>.0.0.1/32,192.168.1.88/24 </span> </li> <li class="alt"> <span class="attribute">zend_debugger.expose_remotely</span><span>=</span><span class="attribute-value">always</span> </li> <li class="alt"><span> </span></li> </ol>
然後重啟apache,在略微的等待之後,我們輸入phpinfo()查看成功與否?