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:
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);
?>
Thanks, for those on unix who would like to save even more time: socket -s 9000
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?
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.
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
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
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.
Thanks Sam, it can be useful for other people.
Regards,
Petr
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
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
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.
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
Sorry, the PHP version number is 5.2.5, of course.
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
Sorry, Petr, for the long answer delay.
$n=10;The answer is: no, it is not. It is a simple script embedded in the usual html tags.
script:
$m=5;
$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).
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.
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...
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?
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...
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?
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
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?
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.
Sorry for the confusion. My message was directed to Tejas not John....
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?
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.
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
Thanks for posting this handy check... new to NetBeans and loving it more by the minute! I'm keeping the file in my little tool stash.
I'm trying to set up php with Netbeans 6.5 using the WAMP stack, as per guidelines to check whether xdebug is installed and working properly, to my misfortune, no message is printed and the script remains running. I am stuck on this for quite a while now trying to investigate the issue. From what little I've explored, xdebug module is recognized by the WAMP, phpinfo() does list the xdebug extension.
Trying to debug from netbeans, results in indefinite wait, for xdebug connection. The script to test xdebug specified above also runs indefinitely without any messages displayed, Socket extension though has been activated.
The Apache log file gives a warning "PHP Warning: Xdebug MUST be loaded as a Zend extension in Unknown on line 0", googled through this nothing substantial or really helpful which would rescue me out of this problem
Am I missing on something which is very silly and going under the nose un-noticed. or are there issues with respect to the php xdebug and netbeans versions. Any pointers on this will be appreciated.
I'm getting this error when I visit my test page @ http://localhost:8080/test_xdebug.php?XDEBUG_SESSION_START=mysession
"Fatal error: Call to undefined function socket_create() in C:\\wamp\\www\\test_xdebug.php on line 4"
Any idea what's wrong here?
Never mind. Fixed it. I needed to uncomment "extension=php_sockets.dll" in my php.ini file.
Thanks to All!! the answer to several of my questions lay in this page :)
any ideas why socket_create is not found even though i've confirmed sockets extension is working from php_info ?
Followed the installation XDebug Wiki and everything worked. XDebug shows up in phpinfo.
Final step is to fire up above test script in your browser. But this test script doesn't work for me it keeps on loading. I spend several hours on it thinking I did something wrong with the installation and setting it up.
Then I decided to just run NetBeans and just try to debug a simple PHP script and what do you think... it just works! So all the time I was thinking my installation was bad because the test script didn't work!!
Can someone explain why I can debug in NetBeans (using XDebug) but the testscript doesn't?
for the fatal error on socket_create even after you enabled the extension :
When using wamp, you have 2 versions of php.ini :
The 1st, editable by right clicking on wamp icon is not used by the PHP command line (cli)
the 2nd php.ini which is CLI dedicated is located in
:\\wamp\\bin\\php\\php5.x.x\\php.ini
You'll need to manually edit this 2nd file and enable extension php_socket manually...
On Windows 7 I am getting MSVCR71.dll, OCI.dll, aspell-15.dll and libc.dll is missing from computer. Why is it missing? Where do I get these DLLs from?
Thank you in advance.
@pit:
I used both ways to test (webbrowser and CLI) and edited both php.ini (C:\\wamp\\bin\\apache\\apache2.2.8\\bin\\php.ini and c:\\wamp\\bin\\php\\php5.2.6\\php.ini). I used same settings in both ini's. None worked. When I run it just waits and nothing happens. If I debug using NetBeans it does work! So I guess your testscript doesn't work?!
XDebug does show up in my phpinfo so the XDebug installation worked.
I am using Windows XP SP3 and WAMP 2.0 (Apache 2.2.8 and PHP 5.2.6).
I use xdebug with IIS7, PHP 5.3, FastCGI. The dll is set up correctly and I can debug php files both in notepad++ using DBG plugin and NetBeans 6.9.
The problem is that I can debug small php files, but when I open my project from existing files NetBeans stay in 'waiting for connection' forever.
I suspect this is not an xdebug problem, but somehow related to NetBeans
Any help?
A user discovered this tip:
- Only use those socket-based php test files like http://blogs.sun.com/netbeansphp/entry/howto_check_xdebug_installation sparingly. When they hang, they can tie up the port and complicate the question. Reboot and restart Apache often. Also, don't forget to try them through a browser as well as the command line. If this gives you a fancy error screen with backtraces and some orange colouring, that's a good sign - that's xdebug at work!
For more information, see alanms' post of 13 August 2010 at http://forums.netbeans.org/viewtopic.php?t=1513&postdays=0&postorder=asc&start=30
Make sure you have selected the correct index.php in your real Web Root" in your application.
Specify this setting by right-clicking on your current Project > Properties > Sources.
This will do the job ... at least for me
I am using netbeans 6.9.1 and configuared xdebugger for php I am getting following message or status after debugger started
waiting for connection(netbeans-xdebug)
can any body help me...
OK, and how do I modify this procedure so that it does NOT go though the server, even a local one, but uses cli-executed scripts at BOTH ends of the connection? I want to debug some PHP code that is designed to work as a command line utility so I do not have a need for all the hassle involved in setting up a web server environment just so I can test whether my xdebug installation works.
Thanks to Radek for dbgtest.php. This allowed me to determine that my 64-bit Windows version of xdebug wasn't loading (although I have a 64-bit machine, xampp is a 32-bit executable). I downloaded the 32-bit version of xdebug and dbgtest.php then confirmed that xdebug is working correctly. Unfortunately, after trying all of the advice in this thread NetBeans IDE 6.9.1 STILL doesn't connect. I'm running Windows 7 with XAMPP 1.7.4.
NetBeans looks like it will be great when it works, but at the moment is just a source of frustration.
I am using NetBeans 6.9.1 with PHP 5.3.5 on Windows and although this blog gives good information, it still doesn't work for me.
When I run the test script dbgtest.php in the command line it doesn't output anything.
How can I debug the dbgtest.php? An echo right after socket_create does not create an out anymore. Does it mean, that the socket_create method already failed?
In phpinfo() it looks that XDEBUG is installed properly with the right attributes (xdebug.remote_enable is on, ...).
Any idea?
Ralph
http://arturito.net/2011/05/21/local-and-remote-php-debuging-in-netbeans-with-xdebug-on-google-chrome-just-like-in-visual-studio/
When I try this code I get this error
Warning: socket_bind() [function.socket-bind]: unable to bind address [0]: Only one usage of each socket address (protocol/network address/port) is normally permitted. in C:\xampp\htdocs\info\xdebug.php on line 5
I am using Xampp 1.7.4 and xdebug 2.1.2 and php 5.3.5.
Is there a way to fix that?
The chrome plugin mentiones by Arturito works nicely (thanks!)... if Netbeans helps a bit, which it doesn't always do. It seems it doesn't always close the socket at port 9000 after ending a debug session, and I believe that's the main reason it sometimes waits forever for a connection. Then the unix "socket" command reports that the port is in use or just doesn't do anything. Using "netstat | grep 9000" or "lsof -n | grep 9000" shows a "java" (i.e. netbeans) connection. The solution I've found (so far) is just to close netbeans, so that port 9000 is no longer used; after restarting it, debugging works fine (so far).