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执行路径
file
设置debug 注意port为9001
file
添加servers
file
设置proxy
file
run->edit
file
添加php web page
file
file
设置打点位置,开始监听
file
start
file
debug会打开浏览器 比如 http://localhost/phpinfo.php?XDEBUG_SESSIO... 每次打开url参数会变
file
结束监听,否则页面一直停留
file
以斐波那契数列为例子,看看循环调用了多少次!

//递归法
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 协议》,转载必须注明作者和本文链接
本帖由系统于 6年前 自动加精
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1
GalaxyNo_1

:sake:

6年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!