PhpStorm + Xdebug = 页面未加载

标签 php xdebug phpstorm

首先,了解一些 xdebug 信息:

Xdebug installed: 2.2.0rc1
Server API: Apache 2.4 Handler Apache Lounge
Windows: yes - Compiler: MS VC9 - Architecture: x86
Zend Server: no
PHP Version: 5.4.0
Zend API nr: 220100525
PHP API nr: 20100525
Debug Build: no
Thread Safe Build: yes
Configuration File Path: C:\Windows
Configuration File: C:\Uniserver\UniServer\usr\local\php\php.ini
Extensions directory: C:\Uniserver\UniServer\usr\local\php\extensions

You're already running the latest Xdebug version

一切看起来都很好。这是我的 php.ini 的样子:

[Xdebug]
zend_extension=C:\Uniserver\UniServer\usr\local\php\extensions\php_xdebug-2.2.0RC1-5.4-vc9.dll
xdebug.remote_host=localhost
xdebug.remote_port=9123
xdebug.idekey=PHPSTORM
xdebug.remote_mode=req
xdebug.remote_handler=dbgp
xdebug.remote_enable=1
xdebug.remote_connect_back=0
xdebug.remote_autostart=0
xdebug.remote_log="C:\Uniserver\UniServer\usr\local\php\extensions\tmp\log.log"
xdebug.overload_var_dump=1
xdebug.trace_format=0
xdebug.show_exception_trace=0
xdebug.default_enable=0

现在,我将尝试使用 PhpStorm 进行调试。首先,我转到设置->PHP->服务器并添加:

Name: localhost
Host: localhost
Port: 8080
Debugger: Xdebug

(是的,我的网站在端口 8080 上运行,否则我会与我正在使用的其他软件发生冲突。)然后我创建一个新的运行/调试配置:

PHP Remote Debug
Name: local
Servers: localhost
Ide key(session id): PHPSTORM

我还使用这个工具创建了一个启动/停止调试书签:http://www.jetbrains.com/phpstorm/marklets/index.html

好的,一切看起来都准备好了,所以我点击了 PhpStorm 中的“调试”按钮。

我项目的主页位于 http://localhost:8080/Project/page/Home.php ,所以我导航到那里。页面加载。我点击书签栏中的开始按钮,重新加载,页面保持空白...

当我在项目中的 home.php 文件上添加断点并再次重新加载时,断点被击中了!我可以跨过、进入...显示所有值。这没有任何问题。但是当我遍历所有断点,或者点击恢复程序,并返回浏览器时,页面完全空白。 HTML 代码如下所示:

<html><head><style type="text/css"></style></head><body></body></html>

这是怎么回事?为什么我正在调试的页面没有呈现?跨过代码有效,正在执行所有 php 和 html,但最后我的浏览器中没有显示任何内容。我计划在位于文件/Project/class/Account.php 中的函数上使用 Xdebugger,但如果不按主页上的按钮我无法到达那里。

为什么不使用你说的 Xdebug 代理?这能解决什么问题吗?好吧,每当我尝试设置一个时,我都会收到此错误:

Xdebug 代理:无法连接到 'localhost:9123' 上的 xdebug 代理

即使我的 Xdebug 代理配置是正确的:

IDE key: PHPSTORM
Host: localhost
Port: 9123

谁能告诉我这是怎么回事?我真的需要这个调试器,因为某些功能由于某种原因无法正常工作,这让我发疯。我需要检查正在传递哪些变量以及它们发生了什么。

编辑

额外信息:当我完成所有代码时,我的调试器说:

Waiting for incoming connection with ide key 'PHPSTORM'

这可能是我的页面未加载的原因吗?

编辑编辑

好的,不用点击调试按钮,我也可以开始监听 PHP 调试连接。这也有效!我的断点被击中,我可以进入...但同样的问题仍然存在:我的网页保持空白,我的调试器最后说“已断开连接”。该问题在任何浏览器中都存在。

编辑编辑编辑

我在调试时发现了其他一些非常奇怪的东西......我可以很好地进入我的代码,直到我点击获取我的数据库实例的函数。数据库类如下所示:

class Database
{
    private static $instance = null;
    private static $conn;

    private function __construct()
    {
        try {
            self::$conn = new mysqli('localhost', 'root', 'root', 'database', '3308');
        } catch (Exception $ex) {
            $errorpager = new CustomPageGenerator();
            $errorpager->generateErrorPage("Connection to database failed. Please try again later.");
        }
    }

    public static function getInstance()
    {
        try {
            if (self::$instance == null) {
                self::$instance = new Database();
            }
            return self::$instance;
        } catch (Exception $ex) {
            $errorpager = new CustomPageGenerator();
            $errorpager->generateErrorPage("Connection to database failed. Please try again later.");
            return false;
        }
    }

    public function query($sql)
    {
        try {
            return self::$conn->query($sql);
        } catch (Exception $ex) {
            $errorpager = new CustomPageGenerator();
            $errorpager->generateErrorPage("Connection to database failed. Please try again later.");
            return false;
        }
    }
}

我感觉我的数据库类可能与此问题有关...每次我点击 getInstance() 函数时,调试都会突然停止,并且我在 Google Chrome 中收到 net::ERR_CONNECTION_RESET 错误。这可能是问题所在吗?

最佳答案

此问题已在 Xdebug 2.2.0RC2 中修复。请升级。

关于PhpStorm + Xdebug = 页面未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10125216/

相关文章:

php - 如何在 PhpStorm 上设置数据库?

php - Laravel Auth::attempt() 总是假的?

php - 防止 netbeans php Debug 在浏览器中打开新选项卡

php - 使用 Xampp 设置 Xdebug 时出错 (Windows 7) - 服务器证书不包含与服务器名称匹配的 ID

php - Xdebug 总是重置与 phpStorm 的 session

git - 使用 : git config --global core. autocrlf false 是否有任何风险或缺点

javascript - PHPStorm 配置 : How to remove background color on embedded html?

php - 如何配置文件管理器插件?

php - mysql_query 说 sql 语法错误,但相同的查询在 mysql 客户端中工作正常

android - 哪个是最适合 Android 应用程序的后端框架?