<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Xdebug on ZRJ | 学习笔记</title>
        <link>https://blog.zrj.me/tags/xdebug/</link>
        <description>Recent content in Xdebug on ZRJ | 学习笔记</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>zh-CN</language>
        <lastBuildDate>Fri, 17 Aug 2012 20:09:29 +0800</lastBuildDate><atom:link href="https://blog.zrj.me/tags/xdebug/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>PHP 的单步调试</title>
        <link>https://blog.zrj.me/posts/2012-08-17-php-%E7%9A%84%E5%8D%95%E6%AD%A5%E8%B0%83%E8%AF%95/</link>
        <pubDate>Fri, 17 Aug 2012 20:09:29 +0800</pubDate>
        
        <guid>https://blog.zrj.me/posts/2012-08-17-php-%E7%9A%84%E5%8D%95%E6%AD%A5%E8%B0%83%E8%AF%95/</guid>
        <description>&lt;p&gt;想着使用 Xdebug 来搞 php 的单步执行，教程看的这里，&lt;a class=&#34;link&#34; href=&#34;http://blog.csdn.net/Eric6/article/details/5932029&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;http://blog.csdn.net/Eric6/article/details/5932029&lt;/a&gt;，有一点需要小注意的是，需要在 IDE 中建立的项目的文件才能调试，在外面拖进去编辑的文件是不能调试的，这点让我瞎忙活了很久。&lt;/p&gt;
&lt;p&gt;但是上面的搭配有一个很大的问题，就是需要从 IDE 内部来发起，我想要的是，在 IDE 上下断点，从浏览器发起，于是就又继续折腾，看到这篇，&lt;a class=&#34;link&#34; href=&#34;http://hi.baidu.com/specialbrian/item/195b421250079d0fb88a1a51&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;http://hi.baidu.com/specialbrian/item/195b421250079d0fb88a1a51&lt;/a&gt; ，唉，顿时觉得好好的一个轻巧的 PHP，被 Zend 这些个大块头软件搞得好臃肿的感觉&lt;/p&gt;
&lt;p&gt;另外，zend optimizer 已经是不支持 php 5.3 的了，改成了 Zend Guard Loader ，在这里，&lt;a class=&#34;link&#34; href=&#34;http://www.zend.com/en/products/guard/downloads&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;http://www.zend.com/en/products/guard/downloads&lt;/a&gt;，使用的话，看这里，&lt;a class=&#34;link&#34; href=&#34;http://www.4wei.cn/archives/1001038&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;http://www.4wei.cn/archives/1001038&lt;/a&gt;，但是依然报错，&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Fatal error: Incompatible file format: The encoded file has format major ID 1, whereas the Loader expects 4 in C:Program FilesApache Software FoundationApache2.2htdocsZendStudioServerstudioindex.php on line 0
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;最后 google 到这里，&lt;a class=&#34;link&#34; href=&#34;http://forums.kayako.com/threads/fatal-error-incompatible-file-format.24870/&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;http://forums.kayako.com/threads/fatal-error-incompatible-file-format.24870/&lt;/a&gt;，于是看起来无解，现在就是 xdebug 单步。。&lt;/p&gt;
&lt;p&gt;===================================================&lt;/p&gt;
&lt;p&gt;2012-08-18 09:56:55 update 事实证明， xdebug 也是可以从浏览器发起的，不得不感叹，xdebug 实在强大，终于解决，记录一下步骤，首先，下载安装 xdebug，然后配置 php.ini 的时候需要注意，不要配成类似 ;extension=php_zip.dll 的形式，不然 phpinfo 页面会报错，而是要配成 zend_extension = &amp;ldquo;C:/php/php-5.3.16/ext/php_xdebug-2.2.1-5.3-vc9-nts.dll&amp;rdquo; 的形式，然后继续配置其他选项，具体的配置说明强烈推荐官方文档 &lt;a class=&#34;link&#34; href=&#34;http://xdebug.org/docs/remote&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;http://xdebug.org/docs/remote&lt;/a&gt; 和 &lt;a class=&#34;link&#34; href=&#34;http://xdebug.org/docs/all_settings&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;http://xdebug.org/docs/all_settings&lt;/a&gt;，最终配成这个样子&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[Xdebug]
; 指定xdebug 扩展文件的位置(路径请根据自己的情况做调整)
zend_extension = &amp;#34;C:/php/php-5.3.16/ext/php_xdebug-2.2.1-5.3-vc9-nts.dll&amp;#34;
; 启用xdebug 远程调试
xdebug.remote_enable = 1
;xdebug.remote_autostart=1
xdebug.remote_log=&amp;#34;C:/php/xdebug/remote&amp;#34;

xdebug.collect_params=4
xdebug.collect_return=on
xdebug.show_local_vars=on

;xdebug.profiler_enable=on
xdebug.profiler_output_dir=&amp;#34;C:/php/xdebug/profile&amp;#34;

;xdebug.auto_trace=on
xdebug.trace_output_dir=&amp;#34;C:/php/xdebug/trace&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;那个 auto_start 可以按需打开，然后配置 IDE，&lt;a class=&#34;link&#34; href=&#34;http://webcache.googleusercontent.com/search?q=cache:vJTnVwvgNh8J:rikugun.iteye.com/blog/254512&amp;#43;xdebug&amp;#43;remote&amp;#43;debug&amp;amp;cd=4&amp;amp;hl=zh-CN&amp;amp;ct=clnk&amp;amp;client=aff-cs-worldbrowser&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;http://webcache.googleusercontent.com/search?q=cache:vJTnVwvgNh8J:rikugun.iteye.com/blog/254512+xdebug+remote+debug&amp;amp;cd=4&amp;amp;hl=zh-CN&amp;amp;ct=clnk&amp;amp;client=aff-cs-worldbrowser&lt;/a&gt; ，这里也有提到怎么配置远程的问题，但是跟着做依然不成功，最后找到这里，&lt;a class=&#34;link&#34; href=&#34;http://bogdan-albei.blogspot.com/2010/06/php-remote-debugging-with-xdebug-and.html&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;http://bogdan-albei.blogspot.com/2010/06/php-remote-debugging-with-xdebug-and.html&lt;/a&gt;，&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Now the tricky part, Eclipse has to be configured to accept debugging sessions from XDebug. Follow the steps below: Open your project in Eclipse PDT In the main menu select Project-&amp;gt;Properties On the left side of the window select &amp;ldquo;PHP Debug&amp;rdquo; and then click on &amp;ldquo;Configure Workspace Settings&amp;rdquo; On the &amp;ldquo;PHP Debugger&amp;rdquo; dropdown select Xdebug and click &amp;ldquo;Apply&amp;rdquo; Click &amp;ldquo;Configure&amp;rdquo; to the right of Xdebug in the same window. Select Xdebug and click &amp;ldquo;Configure&amp;rdquo;. On the &amp;ldquo;Accept remote session(JIT)&amp;rdquo; select &amp;ldquo;any&amp;rdquo; and click &amp;ldquo;OK&amp;rdquo;. This is extremely important and this is where most people get stuck. That&amp;rsquo;s it, Eclipse is now configured, now all we need is to be able to be in control of our debugging sessions. For this we will need to install a Firefox extension called &amp;ldquo;easy Xdebug&amp;rdquo;(yes Firefox, you&amp;rsquo;re not developing PHP in IE are you?).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;重点就在那个 Accept remote session ，打开之后，就能够从浏览器发起一个请求，转入 IDE 的调试界面了。&lt;/p&gt;
&lt;p&gt;而他的工作原理其实是这样的，我们把浏览器所在的机子叫做 local，把跑着 php 脚本的机子叫做 server 的话，xdebug 在 server 上，当我们从浏览器发起一个请求后，到达 server，xdebug 把这个请求拦截下来，然后转入单步运行状态，然后连接回 IDE 所在的机子上的 9000 端口，IDE 则一直监听在 9000，一旦得到信号，就转入 debug 页面，从而完成一个调试过程&lt;/p&gt;
&lt;p&gt;除了 auto_start，还有另外一种方式，官方文档说，&lt;/p&gt;
&lt;blockquote&gt;
&lt;h2 id=&#34;http-debug-sessions&#34;&gt;HTTP Debug Sessions
&lt;/h2&gt;&lt;p&gt;Xdebug contains functionality to keep track of a debug session when started through a browser: cookies. This works like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When the URL variable &lt;code&gt;XDEBUG_SESSION_START=name&lt;/code&gt; is appended to an URL Xdebug emits a cookie with the name &amp;ldquo;XDEBUG_SESSION&amp;rdquo; and as value the value of the XDEBUG_SESSION_START URL parameter. The expiry of the cookie is one hour. The DBGp protocol also passes this same value to the init packet when connecting to the debugclient in the &amp;ldquo;idekey&amp;rdquo; attribute.&lt;/li&gt;
&lt;li&gt;When there is a GET (or POST) variable XDEBUG_SESSION_START or the XDEBUG_SESSION cookie is set, Xdebug will try to connect to a debugclient.&lt;/li&gt;
&lt;li&gt;To stop a debug session (and to destroy the cookie) simply add the URL parameter&lt;code&gt;XDEBUG_SESSION_STOP&lt;/code&gt;. Xdebug will then no longer try to make a connection to the debugclient.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p&gt;另外的文章可以参考这里，&lt;a class=&#34;link&#34; href=&#34;http://hi.baidu.com/icejmx/item/2af1a6a6f7a6ff248819d314&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;http://hi.baidu.com/icejmx/item/2af1a6a6f7a6ff248819d314&lt;/a&gt;，是 xdebug 的简介，这里，&lt;a class=&#34;link&#34; href=&#34;http://www.jb51.net/article/24199.htm&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;http://www.jb51.net/article/24199.htm&lt;/a&gt; 是一些配置选项的中文说明，&lt;/p&gt;
&lt;p&gt;===========================================================&lt;/p&gt;
&lt;p&gt;2012-08-18 15:00:49 update 使用这个 debug 有一个问题，在于会出现 unexpected termination of script, debugging ended 的提示，google 一下看到这里也有人在吐槽，&lt;a class=&#34;link&#34; href=&#34;http://stackoverflow.com/questions/5962060/error-message-unexpected-termination-of-script-debugging-ended-when-debuggi&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;http://stackoverflow.com/questions/5962060/error-message-unexpected-termination-of-script-debugging-ended-when-debuggi&lt;/a&gt;，虽然里面有人说换个低版本可以解决，但是我换了还是不行，估计真的是个 bug&lt;/p&gt;
</description>
        </item>
        
    </channel>
</rss>
