PhpStorm + Xdebug = page not loading
php, phpstorm, xdebug
Solution
From what you describe, xdebug remote debugging works.
Why that HTML is returned to the browser (and not what you expect) is hard to say. Have you tried using a stable version of xdebug?
Problem
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?