<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Doctor's WebLog]]></title> 
<link>http://www.gaobo.info/index.php</link> 
<description><![CDATA[博乐的自留地]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Doctor's WebLog]]></copyright>
<item>
<link>http://www.gaobo.info/read.php/537.htm</link>
<title><![CDATA[PHP Remote Debugging - Xdebug]]></title> 
<author>Doctor &lt;gregry@cqut.edu.cn&gt;</author>
<category><![CDATA[PHP&amp;DB&amp;...]]></category>
<pubDate>Thu, 21 Aug 2008 09:37:55 +0000</pubDate> 
<guid>http://www.gaobo.info/read.php/537.htm</guid> 
<description>
<![CDATA[ 
	<p>PHP Remote Debugging，另一个比较流行的调试模块是<a href="http://xdebug.org/"><span style="color: #225588">Xdebug</span></a>。Xdebug，使用上非常方便，在遇到exception的时候，能够将Application当前的状况，变量、call trace等信息，友好地直接输出到web页面上。</p><p>从<a href="http://xdebug.org/"><span style="color: #225588">Xdebug</span></a>上下载Xdebug for PHP的扩展模块，将其置于PHP的ext目录中。在php.ini中增加，</p><blockquote><pre style="font-size: 100%; font-family: courier new">extension=php_xdebug.dll<br /><br />xdebug.show_exception_trace=on<br />xdebug.show_local_vars=on</pre></blockquote><p>这样就可以在Web Application遇到语法或值溢出等exception的时候，显示相关变量和调用堆栈。</p><p>对于PHP Remote Debugging，需要在php.ini中对Xdebug进行更多的设置。</p><blockquote><pre style="font-size: 100%; font-family: courier new">zend_extension_ts=&quot;ext/php_xdebug.dll&quot;<br />xdebug.remote_enable=1<br />xdebug.remote_handler=dbgp<br />xdebug.remote_mode=req<br />xdebug.remote_host=127.0.0.1<br />xdebug.remote_port=9000<br />xdebug.idekey=&lt;idekey&gt;<br />xdebug.show_exception_trace=on<br />xdebug.show_local_vars=on<br />xdebug.show_mem_delta=on</pre></blockquote><p>并将和Zend Optimizer有关的选项全部关闭。在phpinfo()中，检查是否成功启动Xdebug。</p><p>Xdebug支持多个调试协议，<a href="http://www.xdebug.org/docs-debugger.php"><span style="color: #225588">GDB</span></a>、<a href="http://www.xdebug.org/docs-dbgp.php"><span style="color: #225588">DBGp</span></a>和PHP3。这里使用的是DBGp，一个基于XML的多语言调试协议。</p><p>目前，Xdebug的最新版本是2.0.0 Beta。和DBG Debugger相比，支持Xdebug的IDE还不太多。这里以<a href="http://www.activestate.com/Products/Komodo/"><span style="color: #225588">Komodo</span></a>为例，说明基于Xdebug扩展，如何进行Remote Debugging。</p><p>安装好Komodo 3.5.3之后，设置Preferences - Debugger - Proxy中的，</p><blockquote><pre style="font-size: 100%; font-family: courier new">Listen for debug connections on port: 9000</pre></blockquote><p>再选择Debug - Listen for Remote Debugger。如果出现勾号，没有出错信息的话，Komodo is ready for remote debugging。</p><p>输入Xdebug调试开始指令，</p><blockquote><pre style="font-size: 100%; font-family: courier new"><a href="http://localhost/myscript.php?XDEBUG_SESSION_START=1" target="_blank">http://localhost/myscript.php?XDEBUG_SESSION_START=1</a></pre></blockquote><p>切换到Komodo，对PHP程序进行在线调试。</p><p>上述指令，会启动一个持续的Xdebug调试session，后续PHP脚本会自动进入在线调试状态。也可以只对单个PHP脚本进行单次Remote Debugging。</p><blockquote><pre style="font-size: 100%; font-family: courier new"><a href="http://localhost/myscript.php?XDEBUG_SESSION_START" target="_blank">http://localhost/myscript.php?XDEBUG_SESSION_START</a></pre></blockquote><p>这样就不需要再输入调试中止指令，直接退出Remote Debugging。调试中止指令，格式如下，</p><blockquote><pre style="font-size: 100%; font-family: courier new"><a href="http://localhost/myscript.php?XDEBUG_SESSION_STOP" target="_blank">http://localhost/myscript.php?XDEBUG_SESSION_STOP</a></pre></blockquote><p>需要指出的是，XDEBUG_SESSION_STOP不会立即停止对当前PHP的在线调试，而是停止对此以后的PHP的Remote Debugging。</p><p>Xdebug提供了一个xdebug_break()函数，直接在程序中设置断点，而不是在Komodo中设置。</p><br/>Tags - <a href="http://www.gaobo.info/go.php/tags/php/" rel="tag">php</a> , <a href="http://www.gaobo.info/go.php/tags/debug/" rel="tag">debug</a> , <a href="http://www.gaobo.info/go.php/tags/xdebug/" rel="tag">xdebug</a> , <a href="http://www.gaobo.info/go.php/tags/%25E8%25B0%2583%25E8%25AF%2595/" rel="tag">调试</a>
]]>
</description>
</item>
</channel>
</rss>