我的vim调试器需要我在浏览器中设置一个Xdebug cookie,通过附加?XDEBUG_SESSION_START=1
,之后我可以开始调试。
但是在CLI中调用脚本时,我不能设置这个cookie/session。
如何调试命令行php脚本与vim?
我没有在一个方便的地方找到这个谜题的所有部分,所以这里是我的稍微完整的解决方案。这适用于我的vim 7.3, xdebug 2.0。
-
获取调试器vim插件
- debug .py文件放在.vim/plugins中,而病菌不会自动执行。
- 使用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
-
在shell中使用XDEBUG_IDEKEY值启动php,使用"php {scriptname}"
php加载php.ini,找到xdebug。extension是用php。ini设置初始化的。xdebug扩展拦截脚本执行,并尝试连接到localhost:9000,这是vim+python扩展正在监听的地方。一旦建立了连接,xdebug扩展将协调调试会话,vim插件将显示一堆类似ide的调试窗口。瞧!
附加链接:我还使用这个shell脚本来启动php。它等待,直到看到vim打开调试端口,然后启动php会话。完成后,它打印结果代码并返回进行另一次运行(当然,除非按ctrl+c)。
我想你会在文档中找到答案(搜索Starting The Debugger
)。