Windows PHPstorm xdebug 断点调试
前几天在站内看到有人写了篇 断点调试文章,于是我也动手学习下。
1.安装扩展xdebug
我用的是phpstudy环境,php版本为 php-7.1.13-nts,选择下载的xdebug为 https://xdebug.org/files/php_xdebug-2.7.0a...
添加到php.ini
[XDebug]
xdebug.profiler_output_dir="D:\php_study\PHPTutorial\tmp\xdebug"
xdebug.trace_output_dir="D:\php_study\PHPTutorial\tmp\xdebug"
zend_extension="D:\php_study\PHPTutorial\php\php-7.1.13-nts\ext\php_xdebug.dll"
xdebug.remote_enable = on
xdebug.auto_trace = On
xdebug.remote_handler = dbgp
xdebug.remote_host = localhost
xdebug.remote_port = 9001
xdebug.idekey = PHPSTORM
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = Off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.show_local_vars=0
2.配置phpstorm
file->setting-> 设置PHP执行路径
设置debug 注意port为9001
添加servers
设置proxy
run->edit
添加php web page
设置打点位置,开始监听
start
debug会打开浏览器 比如 http://localhost/phpinfo.php?XDEBUG_SESSIO... 每次打开url参数会变
结束监听,否则页面一直停留
以斐波那契数列为例子,看看循环调用了多少次!
//递归法
function fib_recursive($n){
if($n==0||$n==1){return 1;}
else{
return fib_recursive($n-1)+fib_recursive($n-2);
}
}
echo fib_recursive(10);
对比下
//数组法
function fib_recursive($num){
$arr=[];
for($i=0;$i<=$num;$i++)
{
if($i==0 || $i==1){
$arr[$i]=1;
}else{
$arr[$i]=$arr[$i-1]+$arr[$i-2];
}
}
return $arr[$num];
}
print_r(fib_recursive(10));
3.问题
如果出现Can't start listening for connections from 'xdebug': Port 9000 is busy
可修改端口号,要修改两个地方
第一个地方是刚才php.ini里面的xdebug.remote_port=9001
第二个地方是phpstorm - setting - Languages&Frameworks -PHP - debug - 修改里面的Debug port
4.感谢:
https://www.cnblogs.com/baocheng/p/5775938...
https://www.cnblogs.com/niuxiaoling/p/8027...
分享:Vagrant phpstorm xdebug
博客:phpstrom xdebug 断点调试教程
https://xiaoxingping.top/book/show/1?id=13
使用phpstorm对docker中的脚本进行debug
本作品采用《CC 协议》,转载必须注明作者和本文链接
:sake: