PHP调试器Vim:调试命令行脚本 [英] PHP debugger for Vim: Debug Commandline scripts

查看:125
本文介绍了PHP调试器Vim:调试命令行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的vim调试器要求我在浏览器中设置一个Xdebug cookie,通过添加?XDEBUG_SESSION_START = 1 ,之后我可以开始调试。

My vim debugger requires me to set an Xdebug cookie in my browser, by appending ?XDEBUG_SESSION_START=1, after which I can start debugging.

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

But I cannot set this cookie/session when calling a script on the CLI.

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

How does one debug commandline php-scripts with vim?

推荐答案

我没有在一个方便的地方找到这个难题的所有作品,所以这里是我的一个更完整的解决方案。这对我来说与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).

这篇关于PHP调试器Vim:调试命令行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆