一、事理
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