Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm + Xdebug = page not loading

First things first, have some xdebug info:

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

Everything looks fine. This is what my php.ini looks like:

[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

Now, I'm going to try to debug with PhpStorm. First I go to Settings->PHP->Servers and add this:

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

(Yes, my website is running on port 8080, otherwise I get conflicts with other software I'm using.) Then I create a new Run/Debug configuration:

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

I also create a start/stop debug bookmark with this tool: http://www.jetbrains.com/phpstorm/marklets/index.html

Ok, everything looks ready, so I hit the Debug button in PhpStorm.

The homepage of my project is located at http://localhost:8080/Project/page/Home.php, so I navigate there. The page loads. I hit the start-button in my bookmarks bar, reload and the page stays blank...

When I add a breakpoint on the home.php file in my project and reload again, the breakpoint gets hit! I can step over, step into,... All the values are displayed.. This works without any issue. But when I went over all the breakpoints, or hit Resume Program, and return the the browser the page is completely blank. The HTML code looks like this:

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

What is going on? Why is the page I'm debugging not being rendered? Stepping over the code works, all the php and html is being executed, yet in the end nothing is shown in my browser. I plan to use the Xdebugger on a function that is located in a file /Project/class/Account.php, but I can't get there without pressing a button on my Homepage.

Why not use an Xdebug proxy you say? Might that solve anything? Well, whenever I try to set one up I get this error:

Xdebug proxy: Cannot connect to xdebug proxy on 'localhost:9123'

Even though my Xdebug proxy configuration is correct:

IDE key: PHPSTORM
Host: localhost
Port: 9123

Can anyone please tell me what's going on? I really need this debugger because there's a certain function that won't work correctly for some reason, and it's driving me insane. I need to check what variables are being passed and what's happening to them.

EDIT

Extra information: When I'm done stepping over all the code my debugger says:

Waiting for incoming connection with ide key 'PHPSTORM'

Might this be the reason my page is not loading?

EDIT EDIT

Ok, instead of hitting the debug button, I can also just start listening to PHP Debug Connections. This works as well! My breakpoints are hit, I can step into... But the same problem persists: My webpage stays blank and my debugger says 'Disconnected' at the end. The problem persists in any browser.

EDIT EDIT EDIT

I've found out something else that's very weird while debugging... I can step into my code just fine until I hit the function that gets my database instance. The Database class looks like this:

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;
        }
    }
}

I get this feeling my database class might have something to do with this issue... Every time I hit the getInstance() function, debugging halts abruptely and I get the net::ERR_CONNECTION_RESET error in Google Chrome. Could this be the issue?

like image 834
Matthias Avatar asked Apr 12 '12 14:04

Matthias


People also ask

How does Xdebug work with PhpStorm?

PhpStorm supports the use of Xdebug in the Just-In-Time (JIT) mode so it is not attached to your code all the time but connects to PhpStorm only when an error occurs or an exception is thrown. Depending on the Xdebug version used, this operation mode is toggled through the following settings: Xdebug 2 uses the xdebug .

How do I know if Xdebug is working?

Given that, you can confirm that xDebug is installed and in place by trying the following: 1) phpinfo() -- this will show you all the extensions that are loaded, including xDebug. If it is there, then it's a safe bet that it's working.


2 Answers

The issue is fixed in Xdebug 2.2.0RC2. Please upgrade.

like image 60
Nikolay Matveev Avatar answered Oct 14 '22 20:10

Nikolay Matveev


  • Symfony 2
  • PhpStorm 4.0.1

I have upgraded to php_xdebug-2.2.1-5.4-vc9.dll and this solved the problem

like image 26
Daniel Mora Avatar answered Oct 14 '22 20:10

Daniel Mora