Debugging PHP using Xdebug and Notepad++

本文介绍如何安装配置Xdebug扩展并结合Notepad++的DBGp插件来实现PHP应用的远程调试与性能剖析。通过简单步骤设置Xdebug及Notepad++插件,即可在本地环境中高效调试PHP代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am sure all of you have used ‘echo’ and ‘print_r’ to debug PHP.

We all know that this way debugging is hard and you need to remember to remove them from production server.

Well, thanks to xdebug you can now debug, and you don’t need expensive or blotted IDE for that, just plain and simple Notepad++ can do the job.open php.ini in wamp

In this post we will setup xdebug and DBGp plugin with Notepad++.

Let’s start by installing xdebug.

  1. Download the latest release of xdebug for PHP version you are using.
  2. Copy xdebug dll file into php’s extension directory, in my case, as I use wamp, it is c:\wamp\php\ext .
  3. Now we need to configure xdebug so that it get recognized by PHP, so open php.ini
  4. Add following at the end of your php.ini file
    [xdebug]
    zend_extension_ts="c:/wamp/php/ext/php_xdebug-2.0.3-5.2.5.dll"
    xdebug.profiler_output_dir = "c:/wamp/tmp/xdebug"
    xdebug.profiler_output_name = "cachegrind.out.%p"
    xdebug.profiler_enable = 0
    xdebug.profiler_append=0
    xdebug.extended_info=1
    xdebug.remote_enable=1
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    xdebug.remote_host=127.0.0.1
    xdebug.remote_port=9000
    xdebug.idekey=xdebug
    xdebug.remote_log="c:/wamp/tmp/xdebug/xdebug_remot.log"
    xdebug.show_exception_trace=0
    xdebug.show_local_vars=9
    xdebug.show_mem_delta=0
    xdebug.trace_format=0
  5. Just create a folder ‘xdebug’ in ‘c:\wamp\tmp’ folder.
  6. Finally restart Apache service .

With these steps you have, finished xdebug installation, it is configured for profiling application and remote debugging. Check documentation to know what all these configuration do, and tweak according to your preference.

 

We will now install DBGP plugin for Notepad++. Make sure you have latest version of Notepad++ is installed.

  1. Download the latest release of DBGp Plugin.
  2. Unzip and move dbgpPlugin.dll file to plugins folder of your notepad++ installation folder, in my case the path is “C:\Program Files\Notepad++\plugins”.
  3. Check out the readme.txt file, that is bundled with plugin, to make sure we don’t miss anything.
  4. Now open Notepad++, and you should see DBGp option in plugins menu.

dbgp plugin for notepad++

Well we are now almost finished with setup, only ting remaining is to configure DBGP to listen to right port and we are done.

Goto “Plugins->DBGp->Config” to open the configuration screen of DBGp plugin.

DBGp Configuration window

Fill the details as shown in the image above. IDE KEY should be same to the one you specified in php.ini settings above. Click Ok and you are done.

To start debugging just add “?XDEBUG_SESSION_START=session_name” at end of you url. ‘session_name’ could be anything you want to keep.

在 Windows 下使用 Notepad++xdebug 调试 php 脚本 转自:http://www.mikespook.com/index.php/archives/98 介绍Notepad++ 是开放源代码的可替代记事本的编辑器。它运行于 MS Windows 环境,支持多种编程语言。可以浏览http://notepad-plus.sourceforge.net/ 了解更多相关信息。 Xdebugphp 的一个扩展,它提供了对 php 脚本进行除错、追踪、检查的各种功能。可以浏览 http://xdebug.org 了解更多相关信息。 下载Notepad++ 下载地址:http://www.baidu.com/link?url=uULkAaYHzZDZSGm8XOlPH8EPhKZCv8mcbQtmU82LssIoYsVDW2MdIi6g1hdcDKjpGacAHz0xtnxWZHuD1HWUEoL9qCFlDPS1jxAqOJ1ZrYe&wd;=&eqid=8c17eb080003c9bf000000035a1919ed Notepad++ 插件 DBGP plugin: http://download.youkuaiyun.com/download/hongjia88/10132543 xdebug:https://xdebug.org/download.php * xdebug 的版本需要匹配环境使用的 PHP 版本。 xdebug helper for firefox:https://addons.mozilla.org/zh-CN/firefox/addon/3960 安装Notepad++ 的安装方式如同大多数 Windows 下软件一样是非常简单的。只需按照屏幕提示设置并点击“下一步”,最后“完成”即可安装成功。 为了让 Notepad++xdebug 协同工作,需要安装 DBGP plugin。下载后只需解压缩至 Notepad++ 安装目录中的 plugins 目录即可,如:C:\Program Files\Notepad++\plugins。 xdebug 的安装请参考:http://www.mikespook.com/index.php/archives/34。需要说明的是,如果同时安装有 xcache 一定要先加载 xcache,再加载 xdebug。否则会造成 php 运行异常。 使用首先,将编写分别使用递归方式和使用循环方式计算100的阶乘的两个函数,如下: <?php function f1($x) // 循环计算 $x 的阶乘 { for($i = $x - 1; $i > 1; $i–) { $x *= $i; } return $x; } function f2($x) // 递归计算 $x 的阶乘 { if($x == 1) { return $x; } else { $y = $x - 1; return $x * f2($y); } } echo ‘f1: ‘ . f1(10); echo ‘’; echo ‘f2: ‘ . f2(10); 将该文件放入可通过 web 访问并由 php 正确解析的目录,访问结果如图: 使用 Notepad++ 打开这个文件。通常在文件上点击鼠标右键(或者左键,如果你跟我一个方向的话),选择“Edit with Notepad++”,如图: 如果你没有这项,或者无法使用 Notepad++,请检查是否正确的安装了 Notepad++。打开后的界面如图: 在 Notepad++ 的菜单“插件”中选择“DBGp”并点击“Debug”: 会在编辑器下半部分打开调试窗口: 此时就已经打开了编辑器端的调试功能。 现在需要配置notepad++,打开DBGp->Debugger->config,填写Remote Server ip为127.0.0.1,IDE Hey留空,Remote Path和Local Path都为存放你的php文件的路径,点击确定,OK。 注意C:\windows\php.ini中“xdebug.remote_port=9000”。 使用XDEBUG_SESSION_START=1参数访问刚才编写的文件,如:http://127.0.0.1/foobar.php?XDEBUG_SESSION_START=1 此时会发现 Notepad++ 窗口会闪烁一下,这说明 Notepad++ 的 DBGp 插件已经生效。将光标放置到需要设置断点的位置,并点击有红点的按钮,光标所在行前会显示一个红点,表示断点行,如图: 此时访问/foobar.php?XDEBUG_SESSION_STAR
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值