我的vim调试器要求我在浏览器中设置一个Xdebug cookie,通过追加?XDEBUG_SESSION_START=1,之后我就可以开始调试了.
但是在CLI上调用脚本时我无法设置此cookie /会话.
如何使用vim调试命令行php-scripts?
我没有在一个方便的地方找到这个拼图的所有部分,所以这是我稍微更完整的解决方案.这适用于vim 7.3,xdebug 2.0.
获取调试器vim插件
在php.ini中使用正确的xdebug相关设置(或许使用备用的php.ini):
Run Code Online (Sandbox Code Playgroud)[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
export 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脚本来启动php.它等待直到它看到vim打开调试端口,然后启动php会话.完成后,它会打印结果代码并循环回来进行另一次运行(当然,除非你按下ctrl + c).