用于Vim的PHP调试器:Debug Commandline脚本

时间:2011-11-24 08:59:43

标签: debugging vim php

我的vim调试器要求我在浏览器中设置一个Xdebug cookie,方法是附加?XDEBUG_SESSION_START=1,之后我就可以开始调试了。

但是在CLI上调用脚本时我无法设置此cookie /会话。

如何用vim调试命令行php-scripts?

2 个答案:

答案 0 :(得分:5)

我没有在一个方便的地方找到这个拼图的所有部分,所以这是我稍微更完整的解决方案。这适用于vim 7.3,xdebug 2.0。

  1. 获取debugger vim plugin

    • debugger.py文件是.vim / plugins,病原体不会自动执行。
    • 使用F5启动vim侦听传入的xdebug连接(默认情况下在端口9000上)
  2. 在php.ini中使用正确的xdebug相关设置(或许使用备用的php.ini)。:

  3. [Zend]
    zend_extension = /full/path/to/xdebug.so
    xdebug.remote_enable = 1
    xdebug.remote_port =9000
    xdebug.remote_host = localhost
    ; We have to turn on remote_autostart when running php from
    ; cli.  That's probably a good reason to keep the cli and apache
    ; versions of php.ini distinct.
    xdebug.remote_autostart=1
    ; idekey can be just about anything, but the value in php.ini needs
    ; to match the value used in the environment that launches php. 
    xdebug.idekey=vim_session
    
    1. 从命令行启动php脚本时,以
    2. 格式预设idekey环境var
        

      导出XDEBUG_IDEKEY =“idekey = vim_session”

      1. 在vim中按F5开始侦听remote_port

      2. 在具有XDEBUG_IDEKEY值的shell中,使用“php {scriptname}”启动php

      3. 所以php加载php.ini,找到xdebug.so扩展名,用这些php.ini设置初始化。 xdebug扩展拦截脚本执行并尝试连接到localhost:9000,这是vim + python扩展正在侦听的位置。建立连接后,xdebug扩展协调调试会话,vim插件会调出一堆类似于ide的调试窗口。瞧!

        加分链接:我还使用this shell scrip来启动php。它等待直到它看到vim打开调试端口,然后启动php会话。完成后,它会打印结果代码并循环回来进行另一次运行(当然,除非你按下ctrl + c)。

答案 1 :(得分:0)

我认为您会找到答案in the docs(搜索Starting The Debugger)。

相关问题