Vim使用XDebug支持Php调试

一、原理

Php调试的方式有很多,最常用的就是通过打印来解决,打印带来的缺陷也比较明显,就是不够直观,而且繁琐,打的不准的话,会浪费很多时间,所以这里给大家介绍一种常用调试方式,利用xdebug来实现,这次我们将和Vim结合,具体原理如下:


二、xdebug安装配置

1、为php安装xdebug.so扩展
wget https://xdebug.org/files/xdebug-2.5.4.tgz
tar xf xdebug-2.5.4.tgz
cd xdebug-2.5.4
phpize
./configure --enable-xdebug
make
cp modules/xdebug.so /usr/lib64/php/modules/

2、配置php
cd /etc/php.d

新建xdebug.ini,填入如下内容:

zend_extension =/usr/lib64/php/modules/xdebug.so
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9010

3、重启php-fpm
sudo service php-fpm restart

三、Vim插件安装配置

往.vimrc中插入

Bundle 'joonty/vdebug'
 
"===================================
"xdebug
"==================================
let g:vdebug_options = {}
let g:vdebug_options["port"] = 9010

在命令模式下,执行BundleInstall

四、具体操作

1、打开你要调试的php文件

2、光标移动到你要调试的行,按下<F10>添加一个行断点

3、按下<F5>,开始调试状态,在vim底下会出现类似下面的信息

4、打开浏览器,输入你的Url,并在末尾添加 ?XDEBUG_SESSION_START=1,例如,http:://localhost/index.php → http://localhost/index.php?XDEBUG_SESSION_START=1

然后刷新页面,在vim中就会看到如下信息:

五、调试指南


<F5>: start/run (to next breakpoint/end of script)
<F2>: step over
<F3>: step into
<F4>: step out
<F6>: stop debugging (kills script)
<F7>: detach script from debugger
<F9>: run to cursor
<F10>: toggle line breakpoint
<F11>: show context variables (e.g. after "eval")
<F12>: evaluate variable under cursor
:Breakpoint <type> <args>: set a breakpoint of any type (see :help VdebugBreakpoints)
:VdebugEval <code>: evaluate some code and display the result
<Leader>e: evaluate the expression under visual highlight and display the result

欢迎关注微信公众号

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值