gpt4 book ai didi

debugging - Vim : Debug Commandline scripts 的 PHP 调试器

转载 作者:可可西里 更新时间:2023-11-01 00:50:37 26 4
gpt4 key购买 nike

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

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

如何使用 vim 调试命令行 php 脚本?

最佳答案

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

  1. 获取 debugger vim plugin

    • debugger.py 文件位于 .vim/plugins 中,病原体不会自动执行此操作。
    • 使用 F5 启动 vim 监听传入的 xdebug 连接(默认在端口 9000 上)
  2. 在 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
  1. 从命令行启动 php 脚本时,以
  2. 的形式预设 idekey 环境变量

export XDEBUG_IDEKEY="idekey=vim_session"

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

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

所以 php 加载 php.ini,找到 xdebug.so 扩展,它是用那些 php.ini 设置初始化的。 xdebug 扩展拦截脚本执行并尝试连接到 localhost:9000,这是 vim+python 扩展监听的地方。建立连接后,xdebug 扩展会协调调试 session ,vim 插件会提供一堆类似 ide 的调试窗口。瞧!

奖励链接:我也使用 this shell scrip t 启动 php。它一直等到看到 vim 打开调试端口,然后启动 php session 。完成后,它会打印结果代码并循环返回以进行另一次运行(当然,除非您按 ctrl+c)。

关于debugging - Vim : Debug Commandline scripts 的 PHP 调试器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8254386/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com