{{ v.name }}
{{ v.cls }}类
{{ v.price }} ¥{{ v.price }}
我们在软件开发的时候,经常要进行调试,其中有一种调试方法就是断点,此时可以用php的xdebug扩展来使用。
1,安装php-xdebug扩展;
sudoapt-getinstallphp-xdebug
安装完成后,用php-v的命令查看结果
php-vphp5.6.30-12~ubuntu16.04.1+deb.sury.org+1(cli)copyright(c)1997-2016thephpgroupzendenginev2.6.0,copyright(c)1998-2016zendtechnologieswithzendopcachev7.0.6-dev,copyright(c)1999-2016,byzendtechnologieswithxdebugv2.5.5,copyright(c)2002-2017,byderickrethans
可以看到已经有xdebugv2.5.5安装好了.
2,在php的配置文件中对xdebug扩展进行配置,这里有两种方式:
a:最直接的方式,是找到php.ini,在最后面加入以下配置项;
sudovim/etc/php/5.6/fpm/php.ini
zend_extension=/usr/lib/php/20131226/xdebug.soxdebug.remote_host=localhostxdebug.remote_port=9100xdebug.remote_enable=1xdebug.remote_autostart=1
b:另一种是在xdebug的配置文件中,加入相同的配置项;
我们可以在/etc/php/5.6/fpm/conf.d中看到
20-xdebug.ini->/etc/php/5.6/mods-available/xdebug.ini
可以进入这个文件中,看到这里已经讲zend_extension的路径添加进去了,将其他配置添加进去
zend_extension=xdebug.so
以上两种方法是等价的,因为php的配置文件会引入各个扩展的配置文件
我们逐项来看看这些配置分别代表什么意思
①xdebug.remote_host=localhost
type:string,defaultvalue:localhost
selectsthehostwherethedebugclientisrunning,youcaneitheruseahostname,ipaddress,or'unix:///path/to/sock'foraunixdomainsocket.thissettingisignoredifxdebug.remote_connect_backisenabled.
supportforunixdomainsocketswasintroducedinxdebug2.6.
选择debug客户端在那个主机上运行,可以设置成一个host名称,ip地址,或者unix域名的路径.如果xdebug.remote_connect_back被设置为enabled时,此host设置将被忽略。
②xdebug.remote_port=9100
type:integer,defaultvalue:9000
theporttowhichxdebugtriestoconnectontheremotehost.port9000isthedefaultforboththeclientandthebundleddebugclient.asmanyclientsusethisportnumber,itisbesttoleavethissettingunchanged.
这是xdebug尝试连接的远程host的端口.9000端口是客户端和随附的debug客户端的默认端口。由于很多客户端都使用这个端口号,这个配置一旦设好,最好保持不变。
③xdebug.remote_enable=1type:boolean,defaultvalue:0thisswitchcontrolswhetherxdebugshouldtrytocontactadebugclientwhichislisteningonthehostandportassetwiththesettingsxdebug.remote_hostandxdebug.remote_port.ifaconnectioncannotbeestablishedthescriptwilljustcontinueasifthissettingwas0.
此开关控制着xdebug是否应该尝试联系debug客户端,这个客户端正在监听配置好的host和port.如果这项配置为0,则当无法连接时,脚本会啥都不做,继续执行。
④xdebug.remote_autostart=1
type:boolean,defaultvalue:0
normallyyouneedtouseaspecifichttpget/postvariabletostartremotedebugging(seeremotedebugging).whenthissettingissetto1,xdebugwillalwaysattempttostartaremotedebuggingsessionandtrytoconnecttoaclient,eveniftheget/post/cookievariablewasnotpresent.
通常你需要使用一个特定的httpget/post变量来启动远程bugging.当此配置为1时,xdebug将永远会试图远程debuggingsession,并尝试连接一个客户端,即便get/post/cookie变量没有出现。
3,重启php服务
sudoservicephp5.6-fpmrestart
4,在ide中添加debug的host和port,进入phpstorm->file->settings->languages&frameworks->servers->+
保存后,此时可以在具体的代码文件页面看到debug的标识,
在这里单击一下,有一个红色的圆圈,代表在此处设置一个断点(breakpoint)
用postman请求到这个文件,可以看到在ide下方,出现了很多信息
这些变量值直接展示出来了,而不要再另外去打断点来查看。