Howto check xdebug installation
Petr in one of his recent entries mentions how to install xdebug in Ubuntu. I would like to add a very simple test how to verify that xdebug is properly installed on any supported platform. Naturally the most straightforward test would be to use debugger in NetBeans PHP IDE. Definitely, but maybe you haven't installed NetBeans yet, so I've decided for different approach - just write a very lightweight test listening to a connection on port 9000 (default one for xdebug). Which language to choose? Not much important but why not PHP? So, here we go:

Now if we have a code (let's choose filename like "dbgtest.php") we can use it. Two simply steps should be enough to verify that xdebug was properly installed:
- run the code from command line (e.g. /usr/bin/php dbgtest.php)
- start debug session for arbitrary file from within a browser window (e.g. http://localhost/index.php?XDEBUG_SESSION_START=mysession)

Nice. Thanks. I look forward to seeing how to configure NetBeans to use Xdebug.
For those who are too lazy to type out the code...
<?php
$address = '127.0.0.1';
$port = 9000;
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($sock, $address, $port) or die('Unable to bind');
socket_listen($sock);
$client = socket_accept($sock);
echo "connection established: $client";
socket_close($client);
socket_close($sock);
?>
Posted by Courtney Miles on July 16, 2008 at 02:19 AM CEST #
Thanks, for those on unix who would like to save even more time: socket -s 9000
Posted by Radek on July 16, 2008 at 09:22 AM CEST #
at the first i apologize for my English writing
my problem is when i start to debugging, my IE want to connect to netbeans javascript debugger web page and in the bottom of my ide show "waiting for connection (netbeans-xdebug)" and its never end.
whats the problem?
Posted by reza on September 11, 2008 at 09:18 AM CEST #
Hi Reza,
if I understand correctly, you want to debug JavaScript not the php code. I'm right? If yes, go to the project properties and switch off the Debug Server Side PHP option in Debug category.
If you want to debug PHP, you have to have installed Xdebugger properly.
Posted by Petr on September 11, 2008 at 05:26 PM CEST #
I have just installed NetBeans for PHP, after some less than ideal experience with PHPEdit.
I have not been able to debug anything however:
The debug process is said to be "waiting for connection (netbeans-xdebug)" and 'its never end' for me also.
Yet PHPEdit is using XDebug mostly without issue on port 9000.
Additionaly if I use your code above and enter the URL http://localhost/xdebug_test.php?XDEBUG_SESSION_START=mysession
In IE I get http 500 internal server error, In firefox just blank output - any comments welcome.
Windows xp sp2
Netbeans (Build 200804221056)
Java: 1.6.0_07; Java HotSpot(TM) Client VM 10.0-b23
apache 2.2.6
php: 5.5.5
xdebug php_xdebug-2.0.2-5.2.5.dll
phpinfor reports:
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
with Xdebug v2.0.2, Copyright (c) 2002-2007, by Derick Rethans
Posted by Andrew Seabrook on September 22, 2008 at 02:05 PM CEST #
Hi Andrew,
the Build 200804221056 is really old. It was a technical preview. I suggest to you to try a latest development build, which is much better.
Regarding the debugging. Is the property xdebug.remote_enable switch on?
Regards,
Petr
Posted by Petr on September 22, 2008 at 02:57 PM CEST #
I run into some problems with config xdebug for using with netbeans. The solution was to remove every 'extension=xdebug.so' from php.ini and load xdebug with 'zend_extension=/compleate/phat/to/xdebug.so'. After that, in the output of phpinfo() ther should not stand 'XDEBUG NOT LOADED AS ZEND EXTENSION'.
Maybe this is helping some other to.
Posted by Sam on October 30, 2008 at 10:40 AM CET #
Thanks Sam, it can be useful for other people.
Regards,
Petr
Posted by Petr on November 02, 2008 at 03:10 PM CET #
Hi Petr, I run into problem with the xdebug for my PHP5 and Netbeans 6.5. I have followed all the instruction that I could find on the net such as download xdebug v2.0.3...put it in the ext folder under PHP dir...change the php.ini...with no help. When I check my php version on command line using php -v, it says i have Zend Engine v2.2.0 ...with Xdebug v2.0.3. I also had fatal error when trying to run your above code. The error was "Call to undefine function socket_create()". Do you have any idea?
Thank you
Posted by Tuyen Truong on December 04, 2008 at 03:39 AM CET #
Hi Tuyen,
there can be more problems. Which OS do you use? Did you disabled the Zend debugger? How did you register the xdebug? As a zend_extension? Go through this discussion. Let me know, if you are success.
Regards,
Petr
Posted by Petr on December 05, 2008 at 01:54 AM CET #
Hi Petr,
Thank you for your answer. The machine I use has win Vista. I search the PHP init file and I don't think I have Zend debugger. If this is not the right place to search for it, please show me how.
I register xdebugger by adding in the init file these lines:
zend_extension_ts="C:\ext\php_xdebug-2.0.5-5.2.5.dll"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
I am new to Netbeans so please bear with me if my question or answer make no sense to you.
Thank you.
Posted by Tuyen Truong on December 11, 2008 at 12:13 AM CET #
Hi, Petr,
I have very similar problems with NetBeans 6.5 PHP-pack and xdebug.
If I want to debug anything at the local server, the debugger ignores all the breakpoints, although the process is running (the connection ocured).
The debugger is properly configured, since it runs perfectly well, if I specify php-cgi as the php-interpreter in the run configuration.
And PHPDesigner (a very fast PHP editor) uses xdebug locally without problems.
I checked Firefox, Opera and IE7 as browsers - breakpoints are ignored, the debugger runs through. Shutting down the firewall produces no effect.
I have PHP 2.5.2 as a part of XAMPP on Vista with Apache 2-ts; in fact I had to leave_ts in the confuguration line for xdebug in php.ini and curiously enough, I had to uncomment the 'extension=php_xdebug.dll'
line, otherwise the apache server permanently crashed.
I'd guess the problem is with NetBeans?
Though I can debug with php.cgi, in principle, it feels annoying ;). I hope this annoyance will soon go.
best
Posted by Anatoli Strigin on December 11, 2008 at 12:47 AM CET #
Sorry, the PHP version number is 5.2.5, of course.
Posted by Anatoli Strigin on December 11, 2008 at 12:49 AM CET #
Hi Tuyen, Anatoli,
I don't have many experience on windows. I suggest to go through this topic http://forums.netbeans.org/topic1513.html . You can find here some hints.
To Tuyen: send to users@php.netbeans.org the html output from phpinfo(), which you get through the Apache.
To Anatoli: in your case it can be something different. Which application do you want to debug? Is it a framework based?
Regards,
Petr
Posted by Petr on December 11, 2008 at 11:14 PM CET #
Sorry, Petr, for the long answer delay.
The answer is: no, it is not. It is a simple script embedded in the usual html tags.
script:
$m=5;
$n=10;
$sum_of_factorials = calculate_sum_of_factorials ($m, $n);
echo "The sum of factorials of the entered integers is " . $sum_of_factorials;
function calculate_sum_of_factorials ($argument1, $argument2) {
$factorial1 = calculate_factorial ($argument1);
$factorial2 = calculate_factorial ($argument2);
$result = calculate_sum ($factorial1, $factorial2);
return $result;
}
function calculate_factorial ($argument) {
$factorial_result = 1;
for ($i=1; $i<=$argument; $i++) {
$factorial_result = $factorial_result*$i;
}
return $factorial_result;
}
function calculate_sum ($argument1, $argument2) {
return $argument1 + $argument2;
}
This is the only file in the project (a test, as it were).
Posted by Anatoli Strigin on January 06, 2009 at 10:35 PM CET #
To Anatoli: The xdebug.dll has to be registered as zend_extension. Crashing Apache on Vista is known problem and sometime can help increase the memory for executing php scripts. Look at this topic http://forums.netbeans.org/topic4740.html . You can find there a solution.
Posted by Petr on January 07, 2009 at 12:11 PM CET #
I thought I was a competent *nix admin but I have no idea what Radek means by "socket -s 9000"!
Anyway, I still haven't resolved my issue but for those who would like a little more feedback than the originally posted code I offer this small enhancement:
<?php
$address = '127.0.0.1';
$port = 9000;
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($sock, $address, $port) or die('Error: ' . socket_strerror(socket_last_error()));
socket_listen($sock);
$client = socket_accept($sock);
echo "connection established: $client";
socket_close($client);
socket_close($sock);
?>
BTW, my error is "Address already in use" but netstat shows nothing listening on 9000 locally. Hmmm...
Posted by Bill on April 04, 2009 at 10:54 PM CEST #
Hello! Xdebug is properly installed and as loading fine by Apache together with zend. Although I definitely have a problem configuring it to work with remote machine, which in turn has dynamic ip.
I put myhost.ddns.com as xdebug.remote_host. Ports and firewalls are properly setup at both ends.
xdebug.remote_handler = gdbp and I also start Netbeans with -J-Dorg.netbeans.modules.php.dbgp.level=400.
No change. Browser (Firefox with netbeans extension) starts and loads page as usual. The only sign of xdebug presence is colored var_dump. Xdebug makes no dump output in browser as well.
Can somebody help?
Posted by Antony on May 30, 2009 at 01:55 PM CEST #
I'm having the same problems as Antony and others... can't connect to the debugger. The dbgtest.php scripts times out. But I do see the coloured var_dump()'s...
Posted by Leon Bogaert on July 15, 2009 at 03:52 PM CEST #
Hi,
So am I.
The test code and socket -s 9000 returns Already in use error.
This Ubuntu 9.04 and xampp 1.7.1 running in irtualBox 3.0.2.
foiled at the very last setup step !!
Anyone sort this issue?
Posted by John R on July 17, 2009 at 04:58 PM CEST #
Hi all,
I've worked out what is happening...
i) as a new user to NetBeans, I didn't realise that "Stop at First Line" is defaulted to Yes, and appears in Options:PHP section. IMHM that's in the wrong place, and should be on the Debug menu
ii) the test code is wrong. I expect that once the program is run, a connection to port 9000 is made by NetBeans (acting as a debug client), so when the test code runs in the PHP page being debugged it tries to open another - which it can't.
Wasted a few hours, but taught me a bit more how PHP debugging works.
Very impressed with NetBeans, by the way. Congratulations and thanks to the team that develops it.
John
Posted by John R on July 18, 2009 at 05:20 PM CEST #
I got the following error from log file. Installation is done on wamp server.
Fatal error: Call to undefined function socket_create()
How can I check the installation now?
Posted by Tejas Sali on August 28, 2009 at 08:46 AM CEST #
Hi John,
I had the same problem of undefined socket_create(). This is most probably due to the fact that sockets are disabled in php regular installation(in WAMP as my case was). You just have to go to your php.ini file(remember there are 2 php.ini files in case of wamp) and uncomment extension=php_sockets.dll
This should make socket_create as a recognized function call for php engine.
Posted by Sumit on August 28, 2009 at 05:04 PM CEST #
Sorry for the confusion. My message was directed to Tejas not John....
Posted by Sumit on August 28, 2009 at 05:05 PM CEST #
I'm running Vista with the latest XAMPP 2.5.8 (which has PHP version 5.3.0). I installed the latest XDEBUG (matching for VC6 and threaded), and modified php.ini accordingly.
When I load a page with phpinfo(), xdebug does not appear on the page.
I tried the test you have, and it hangs when trying "socket_accept", and says "Transferring data from localhost..."
Do you know what the problem is?
Posted by Quinn on August 28, 2009 at 10:56 PM CEST #
It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of post. I will be your loyal reader. Thanks again.
Posted by links of london on October 30, 2009 at 03:07 AM CET #
Hello Radek Matous,
Thank you for the script. Unfortunately I have problems to verify my xdebug installation. After running your script no message was printed in the browser window. Could you suggest the steps, how to troubleshoot this problem.
Thank you
Here is my configuration:
Wamp server verxion 2.0h
I downloaded and installed php_xdebug-2.0.5-5.2.dll
My Php.ini
zend_extension_ts="C:/wamp/bin/php/php5.2.9-2/ext/php_xdebug-2.0.5-5.2.dll"
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_log=C:\wamp\logs\xdebug.log
Posted by Steve Smith on November 17, 2009 at 10:35 AM CET #