且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP调试器Vim:调试命令行脚本

更新时间:2023-02-22 10:49:15

我没有在一个方便的地方找到这个难题的所有作品,所以这里是我的一个更完整的解决方案。这对我来说与vim 7.3,xdebug 2.0。

I have not found all the pieces for this puzzle in one convenient place, so here's my slightly-more-complete solution. This works for me with vim 7.3, xdebug 2.0.


  1. 获取调试器vim插件


  • debugger.py文件进入

  • 使用F5启动vim监听传入的xdebug连接(默认端口9000)

在php.ini中使用正确的xdebug相关设置(也可以使用另一个php.ini):

Use the right xdebug-related settings in php.ini (use an alternate php.ini, perhaps).:




[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脚本时,以




的形式预设idekey环境变量导出XDEBUG_IDEKEY =idekey = vim_session

export XDEBUG_IDEKEY="idekey=vim_session"




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

  1. Press F5 in vim to start listening on the remote_port

在具有XDEBUG_IDEKEY值的shell中,使用php {scriptname}

In the shell with the XDEBUG_IDEKEY value, start php with "php {scriptname}"

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

So php loads php.ini, finds the xdebug.so extension, which is initialized with those php.ini settings. The xdebug extension intercepts the script execution and tries to connect to localhost:9000, which is where the vim+python extension is listening. Once a connection is established, the xdebug extension coordinates the debugging session, and the vim plugin puts up a bunch of ide-like debugging windows. Voila!

奖金链接:我也使用此shell脚本启动php。它等待它看到vim打开调试端口,然后启动php会话。完成后,它打印结果代码并循环回来进行另一次运行(当然,除非你点击ctrl + c)。

Bonus link: I also use this shell script to launch php. It waits until it sees vim open the debug port, and then starts the php session. Upon completion, it prints the result code and loops back for another run (unless you hit ctrl+c, of course).