我的 vim 调试器要求我在浏览器中设置 Xdebug cookie,方法是附加?XDEBUG_SESSION_START=1
,之后我就可以开始调试了。
但在 CLI 上调用脚本时我无法设置此 cookie/会话。
如何使用 vim 调试命令行 php 脚本?
我还没有在一个方便的地方找到这个难题的所有部分,所以这是我稍微更完整的解决方案。这对我来说适用于 vim 7.3、xdebug 2.0。
-
Get the 调试器 vim 插件 http://www.vim.org/scripts/script.php?script_id=1929
- debugger.py 文件位于 .vim/plugins 中,该 Pathogen 不会自动执行。
- 使用 F5 启动 vim 监听传入的 xdebug 连接(默认在端口 9000 上)
在 php.ini 中使用正确的 xdebug 相关设置(也许使用备用 php.ini):
[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
- 从命令行启动 php 脚本时,在表单中预设 idekey 环境变量
导出 XDEBUG_IDEKEY="idekey=vim_session"
在vim中按F5开始监听remote_port
在具有 XDEBUG_IDEKEY 值的 shell 中,使用“php {scriptname}”启动 php
因此 php 加载 php.ini,找到 xdebug.so 扩展,该扩展是使用这些 php.ini 设置初始化的。 xdebug 扩展拦截脚本执行并尝试连接到 localhost:9000,这是 vim+python 扩展正在侦听的位置。一旦建立连接,xdebug 扩展就会协调调试会话,vim 插件会显示一堆类似 ide 的调试窗口。瞧!
奖金链接:我也用这个 shell 脚本 https://raw.github.com/Stabledog/bin-pub/master/php-vim-debugt 启动 php。它会等到看到 vim 打开调试端口,然后启动 php 会话。完成后,它会打印结果代码并循环返回以进行另一次运行(当然,除非您按 ctrl+c)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)