简单说下为什么要用debug断点调试,很多人在用var_dump、echo、exit 等来断点调试,当你需要知道多个参数变化及多处打印时,这样就有点心有余而力不足。安装debug就能很好的解决这些问题。
一,php安装debug
1、官网下载地址 : https://xdebug.org/download ,如果分不清版本官网还提供了 custom installation instructions.功能方便顺利引入,我这里就使用custom installation instructions
2、重复phpinfo()页面的所有放入框内,点击 Analyes my phpinfo() output
3、分析页面下载xdebug
4、配置xdebug
[xdebug]
;xdebug3后 很多不在是xdebug.remot,而是xdebug.client_
;xdebug 监听端口 不要和fastcgi端口冲突,默认端口 9000,
xdebug.remote_port=9100
;使用postMan需要传递的cookie参数
xdebug.idekey="PHPSTORM"
;远程主机
xdebug.remote_host="127.0.0.1"
;开启远程调试
xdebug.remote_enable=1
;调试器协议
xdebug.remote_handler="dbgp"
;debug 扩展路径
zend_extension="D:/server/php/ext/php_xdebug.dll"
;开启自动跟踪回溯 (默认关闭 off)
xdebug.auto_trace=1
;是否应收集传递给函数的参数:0没有
;1元素的类型和数量
;2元素的类型和数量,以及完整信息的工具提示
;3完整变量内容
;4完整的变量内容和变量名称。
;5PHP将变量内容序列化,没有名称。
xdebug.collect_params=1
;目录中创建文件
;日志信息输出目录
xdebug.profiler_enable=1
xdebug.profiler_output_dir="D:/server/php/debug"
;当为1时跟踪文件将被追加,而不是在后续请求中被覆盖。
;文件的名称
;跟踪输出文件目录
xdebug.trace_options=1
xdebug.trace_output_name= trace。%c
xdebug.trace_output_dir="D:/server/php/debug"
5、phpinfo 能到xdebug表示安装成功
二、设置phpstorm的debug,
1、phpstorm 设置php环境,选择phpstom菜单file->Settings->Languages & frameworks->php,设置php.exe文件
2、phpstorm 设置php debug端口,选择phpstom菜单file->Settings->Languages & frameworks->php->Debug,设置debug port 为php 配置文件里加xdebug.remote_port要一至。
3、phpstorm 设置php Servers,选择phpstom菜单file->Settings->Languages & frameworks->php->Servers,设置对应的参数。
4、phpstorm 使用需要header 里传入Cookie=XDEBUG_SESSION=PHPSTORM
5、运行测试