Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » How to Debug with Eclipse and PDT, specifically how to use the Built-in Server
How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827178] Sat, 09 May 2020 12:30 Go to next message
Bernd Wechner is currently offline Bernd WechnerFriend
Messages: 14
Registered: May 2020
Junior Member
I admit I'm bamboozled. I have a PHP project I'd like to work on. It's pre-existing and I use Eclipse regularly already (mostly with PyDdev). So I installed the P{HP Development Tools (PDT) but I cannot for love or money work out how to debug with it.

Yes I have read this:

https://help.eclipse.org/2020-03/index.jsp?topic=%2Forg.eclipse.php.help%2Fhtml%2Fgetting_started%2Fbasic_tutorial%2Findex.html

And also this:

stackoverflow.com/questions/4494956/is-there-a-web-server-plugin-for-eclipse/4495010#comment109124215_4495010

i.e. someone who also tried and gave up abandoning PHP for Python because debugging with PDT was beyond him and the most helpful comment he got was "it's possible".

Here's where I'm at. I have a PHP project. I can right click a file (index.php say) then Debug As and then PHP Web Application. I am then asked for a Launch URL, and can click OK.

The friendly thing then just complains:

**Launch Error**
Launch configuration 'index' could not be started in debug mode. There is no debugger specified in corresponding 'Default PHP Web Server' server configuration.

No problem,. Eclipse is a wonderful, powerful free IDE and we know it's a little rough at the edges and so off we go to Window>Preferences>PHP>Servers and click Default PHP Web Server, then Edit and Debugger select Xdebug because we thought ahead and installed that earlier. Then Finish, Apply & Close, and try to debug index.php again.

And voila something actually pops up on Eclipses internal browser but it just says
Could not connect: Connection refused


and is pointing art the URL we provided with "?XDEBUG_SESSION_START=ECLIPSE_DBGP&KEY=15890254748811" appended.

No real surprise as on it's pointing at "http://localhost/.../index.php?..." and on localhost I have no webserver listening on port 80.

This is what a Built-in Server is for!

I notice (through diligent poking around and no luck at all searching on-line) that on the Run menu, Debug Configurations opens the Create, manage and run configurations window, on which is an entry PHP Built-in Server. Right click that and New Configuration and there's one listed called New_configuration.

Getting warm we think, so click New_configuration, and on the right is a panel four tabs, Server, Source, Environment and Common. Screenshot attached.

There is a conspicuous drop down beside the label Server: on the Server tab which is displayed by default. It is blank, and disabled. Great. Looks totally unconfigurable. But hey, we have a Built-in server called New_configuration now, so close, check the setting stuck, and try Debugging again.

Same deal. Opens an internal browser and displays only "Could not connect: Connection refused".

Shrug. Great stuff. Easy no? Find no clues on-line only stuff that says it should work. Like this lovely tutorial:

https://help.eclipse.org/2020-03/index.jsp?topic=%2Forg.eclipse.php.help%2Fhtml%2Fgetting_started%2Fbasic_tutorial%2Findex.html

That just shows me a picture of that same dialog but it lists Local Apache (but no I don't want to install Apache just to work on this PHP project sorry).

So I try another tack. PHP of course, has it's own built-in server, which is just what we need.

So I run `php -S localhost:80` and confirm it's listening by browsing to http://localhost with my web browser, and yep, it loads index.php just fine. Works like a charm. A built-in server that acrually serves unlike the Eclipse PHP Build-in Server!

And voila, now when I try and debug, the index.php renders in Eclipse.

Wow! I'd rather it rendered in my browser the way PyDev does and Visual Studio does, as it's nice to have a workspace on one screen and the browser on the other, but I digress (I would like to fix that though).

Of course now the ultimate test. Set a breakpoint in index.php right at the start, terminate the debugger, start again.

The page loads and renders but my breakpoint never breaks. In fact if it did the page would not have rendered as it's at the start of the file.

So I am bamboozled.

  1. I have no idea what's up with Eclipses PHP Build-in Server? Where is that? How does that even try to work?
  2. Why won't it break on breakpoints when run my own minimal server? Renders the pages fine, won't break?
  3. How do we get PDT to launch it in our default browser or just (as Pydev does and as PHP itself does,),tell us what it's serving on and let us browse there in our chosen browser?

Why is this all so hard? How is it that PHP web development in Eclipse is so obtuse? What should I have read and have failed to find?

Sorry this post is so long. I really want to help you help me, by sharig the whole experience with you, so you can (please) point out what I did wrong and can do right.


Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827187 is a reply to message #1827178] Sat, 09 May 2020 20:41 Go to previous messageGo to next message
Dawid Pakula is currently offline Dawid PakulaFriend
Messages: 291
Registered: March 2013
Senior Member
Default PHP Server != Built-in PHP Server.

Built-in php server support was donated by community, but currently is extremely buggy and require some love. In current state it use some kind of deploy and on each run/refresh during internal copy. So due this is not widely promoted. Anyway, It can be configured via Servers tab. If is not available use Window -> Show View -> Other.

"Default PHP Server" (and other registered in Settings -> PHP -> Servers) is generally used for patch mapping. Mostly for remote debugging. We had discussion in past to clean this up, but we need volunteer ;) Maybe after migration to GitHub we will find someone.

Browser configuration is available in Settings -> General -> Web browser. You can decide how webpages are opened (internally or externally).

In general PDT by default is waiting for incoming localhost debugger requests. So for now I suggest different approach:
1. Make sure you configured Xdebug correctly
2. Run php with -S manually, or via Eclipse External Tools Configuration
3. Use browser plugin (easy debug or similar) to start/stop debugging



Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827190 is a reply to message #1827187] Sun, 10 May 2020 01:37 Go to previous messageGo to next message
Bernd Wechner is currently offline Bernd WechnerFriend
Messages: 14
Registered: May 2020
Junior Member
David, thank you kindly for the rapid and informative response. It does fill me with a few more questions I admit.

I am happy of course to run the "php -S" server, though if I can configure it to start this server automatically what a nice slick boon. So I looked for External Tools as suggested by find only the attached. Namely a dialog that offers no configuration at all alas. What am I missing there?

Launching via external browser I have now done,a nd thank you deeply for the tip. it is in Window>Preferences>General>Web Browser. tested and works. Great tip! Appreciated.

What is this browser plugin you speak of? Any further information, or links?

Is Xdebug configured correctly? As far as I can tell it is. But how do I detect this. For example an extract from "php -i" reports:

xdebug

xdebug support => enabled
Version => 2.9.5
Support Xdebug on Patreon, GitHub, or as a business: https://xdebug.org/support

Debugger => enabled
IDE Key => bernd

Directive => Local Value => Master Value
xdebug.auto_trace => Off => Off
xdebug.cli_color => 0 => 0
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.coverage_enable => On => On
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.file_link_format => no value => no value
xdebug.filename_format => no value => no value
xdebug.force_display_errors => Off => Off
xdebug.force_error_reporting => 0 => 0
xdebug.gc_stats_enable => Off => Off
xdebug.gc_stats_output_dir => /tmp => /tmp
xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p
xdebug.halt_level => 0 => 0
xdebug.idekey => no value => no value
xdebug.max_nesting_level => 256 => 256
xdebug.max_stack_frames => -1 => -1
xdebug.overload_var_dump => 2 => 2
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_enable_trigger => Off => Off
xdebug.profiler_enable_trigger_value => no value => no value
xdebug.profiler_output_dir => /tmp => /tmp
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_addr_header => no value => no value
xdebug.remote_autostart => Off => Off
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => Off => Off
xdebug.remote_host => localhost => localhost
xdebug.remote_log => no value => no value
xdebug.remote_log_level => 7 => 7
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
xdebug.remote_timeout => 200 => 200
xdebug.scream => Off => Off
xdebug.show_error_trace => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.trace_enable_trigger => Off => Off
xdebug.trace_enable_trigger_value => no value => no value
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => /tmp => /tmp
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3


Which, when I look at it suggest the IDE key may be wrong. Didn't see that mentioned anywhere in xdebug config, nor do I see a way to configure in Eclipse without nominating a proxy.

Could this be the sole reason breakpoints aren't firing and if so what is the recommended approach and where did I fail to read about it? Do I reconfigure xdebug or Eclipse? And does this relate to the URL get params Eclipse throws at the page "XDEBUG_SESSION_START=ECLIPSE_DBGP&KEY=15890254748811"

If so, where can I read a little more on what that means? I'll dig around the xdebug docs next I guess. But I'm still puzzled at why this is proving so difficult.

I'm also I admit puzzled why so much of what I read suggest zend debugger when all I can find on-line is that it's commercial and comes with fees where xdebug is FOSS and I can't see any comparisons or recommendations bar one discsussion I found in which folk agreed it was much of a muchness. I shall keep good notes on this if I get it working so I'm in a position to support newbs in the field like me, maybe publish a post with setup recommendations. But first I have to get it working!
Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827191 is a reply to message #1827190] Sun, 10 May 2020 02:10 Go to previous messageGo to next message
Bernd Wechner is currently offline Bernd WechnerFriend
Messages: 14
Registered: May 2020
Junior Member
An update. Huge progress, but still stuck. I found this (again):

https://wiki.eclipse.org/Debugging_using_XDebug

I noticed in my "php -i " dump above:

xdebug.remote_enable => Off => Off


So following the help on that page I added:
xdebug.remote_enable = on
xdebug.remote_handler = dbgp


to my .ini file and observe two things:

1) the first setting sticks, the second is not reported. Suggests to me that setting is not supported in xdebug 2.9.5, the help is based on 2.2.1.

2) It breaks! On the first line of my PHP file. Yay! BUT. If I continue or try to single step it does neither, it just hangs. Grrrr.

So I went to Window>Preferences>PHP>Debug and turned off Break at First Line, and tried again. It still breaks on first line... weird. Closed Eclipse and strated agai, checked the setting was off and tried again, it still breaks on first line. great setting,.

So it seems now I have it breaking on first line whether I want to to not, and unable to continue (F8) or single step (F6 or F5) (via keys or menus or toolbar).

I call that progress of a sort. But I'm still shy of being able to debug PHP and would appreciate any pointers!


Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827197 is a reply to message #1827191] Sun, 10 May 2020 11:20 Go to previous messageGo to next message
Dawid Pakula is currently offline Dawid PakulaFriend
Messages: 291
Registered: March 2013
Senior Member
For firefox: https://addons.mozilla.org/en-US/firefox/addon/xdebug-helper-for-firefox/

For chrome: https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc?hl=en

Setup built-in server:
1. Go to external tools configuration
2. Select program
3. Add new (icon on top left)
4. Setup location, for example: /usr/local/bin/php74
5. Setup working directory, for example: /Users/username/www/my_proect
6. Add arguments, for example -S localhost:8080
7. On common tab make sure "Allocate console" is checked (this is default)

You can also pin this config to external button. No play and go to localhost:8080. Output will be inside allocated console. Program will stop if you close eclipse.


Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827198 is a reply to message #1827197] Sun, 10 May 2020 11:22 Go to previous messageGo to next message
Dawid Pakula is currently offline Dawid PakulaFriend
Messages: 291
Registered: March 2013
Senior Member
Settings "break at first line" is used as default for JIT and fresh debug/run configuration. If you launch debugger through "debug" button or if jit detects it, configuration in "debugger" tab will be used, so make sure this settings is correctly setup.

Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827199 is a reply to message #1827198] Sun, 10 May 2020 12:19 Go to previous messageGo to next message
Bernd Wechner is currently offline Bernd WechnerFriend
Messages: 14
Registered: May 2020
Junior Member
Thanks enormously David. Paying keen attention and eager. But do note that I cannot see the External Tools configuration. All I see is this:

https://www.eclipse.org/forums/index.php?t=getfile&id=38076&

Am I looking in the right place? Is something broken?
Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827200 is a reply to message #1827199] Sun, 10 May 2020 12:21 Go to previous messageGo to next message
Dawid Pakula is currently offline Dawid PakulaFriend
Messages: 291
Registered: March 2013
Senior Member
If you use Eclipse for PHP package you should see "external tools" button right after "profiling, on toolbar: debug, run, profile, external tools.

See also: https://help.eclipse.org/2020-03/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-exttools-running.htm

We definitely have to improve/introduce "out of box" experience. Another task on my enormous TODO ;)


Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827201 is a reply to message #1827200] Sun, 10 May 2020 12:24 Go to previous messageGo to next message
Dawid Pakula is currently offline Dawid PakulaFriend
Messages: 291
Registered: March 2013
Senior Member
Example configuration screen

Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827202 is a reply to message #1827201] Sun, 10 May 2020 12:37 Go to previous messageGo to next message
Bernd Wechner is currently offline Bernd WechnerFriend
Messages: 14
Registered: May 2020
Junior Member
Thanks, External Tools rocks, added it now. Indeed, I am taking notes for a quick start guide ;-).

I still have to work out why I can't continue or single step. I see xdebug can keep a log file too, and I'll look into the browser helpers! Alas end of day of me here and must retire. Tomorrow perhaps I'll continue pottering on it.
Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827203 is a reply to message #1827202] Sun, 10 May 2020 12:42 Go to previous messageGo to next message
Bernd Wechner is currently offline Bernd WechnerFriend
Messages: 14
Registered: May 2020
Junior Member
Like wow, I installed the xdebug-helper and clicked the little bug and made it green and now I CAN single step! Blows me away.

Quick question: Can we explain what happened there? Do you need the browser extension for single stepping to work? Just to get clear in my head what happened.
Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827204 is a reply to message #1827203] Sun, 10 May 2020 12:47 Go to previous messageGo to next message
Dawid Pakula is currently offline Dawid PakulaFriend
Messages: 291
Registered: March 2013
Senior Member
chrome / firefox plugin only create/remove cookie XDEBUG_SESSION=1. In theory same thing do XDEBUG_SESSION_START/ XDEBUG_SESSION_STOP in GET request.
If debug enabled, xdebug trying to connect localhost:9000, if you use remote_connect_back, it will try your_ip:9000.

Eclipse by default listen on this port on 127.0.0.1, accept incoming connection, and auto-create debug session. Because you disabled "stop on first line" It didn't stop on first.

So everything just works with defaults, this is simplest way to make this work.


Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827205 is a reply to message #1827204] Sun, 10 May 2020 12:51 Go to previous messageGo to next message
Dawid Pakula is currently offline Dawid PakulaFriend
Messages: 291
Registered: March 2013
Senior Member
BTW: Same plugin allows you simply start "profiling session". Profiling session will create cache grind file that you have to import manually: https://help.eclipse.org/2020-03/topic/org.eclipse.php.help/html/tasks/profiling/importing_profile_sessions.html

Trace file isn't supported right now.


Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827227 is a reply to message #1827205] Mon, 11 May 2020 06:49 Go to previous messageGo to next message
Bernd Wechner is currently offline Bernd WechnerFriend
Messages: 14
Registered: May 2020
Junior Member
If I understand right, xdebug, a php module will, if asked to via a GET param, connect to port 9000 on localhost and send an update like "Have stopped execution at line X of file Y" and then Eclipse will send back an instruction based on whether I pres F8 (continue), or F6 (step over) or F5 (step into) or F7 (run to end of method), xdebug does so and sends back "cool now I'm line X of file Y".

But how does eclipse send this message to xdebug?

And is it the case the xdebug knows to open port 9000 when XDEBUG_SESSION_START=ECLIPSE_DBGP and KEY=15890254748811 are in the GET params? Where's this documented?

Or if I turn debugging on with the button in the browser, it opens port 9000 and starts debugging regardless of the GET params? And automatically breaks on first line of the loaded file?

I'd love to find a brief run through how this all works. Because it's a dream come true when it does and has been a real pain to get that far. I want some learning out of it too I guess.

Of course Eclipse also shows all the values of variables in the context of the break point and so I guess xdebug sends those through too on port 9000. And I can enter arbitrary expressions too, which clearly Eclipse by some means sends to php (and xdebug) and ti sends back the result on port 9000?

Thanks so much for patience here with a PHP noob. To be honest I've used Python debugging with PyDev for eyars and it just works out of the box so never engaged this level of learning but also want it as I start wanting remote debugging in Python, but that's another story.

Main questions are it seems xdebugsends messages to ecliplse on a nominated port (default 9000) and host (default localhost). But how does eclipse send messages to xdebug? And is this protocol documented somewhere? Keen student.
Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827228 is a reply to message #1827227] Mon, 11 May 2020 07:05 Go to previous messageGo to next message
Dawid Pakula is currently offline Dawid PakulaFriend
Messages: 291
Registered: March 2013
Senior Member
Xdebug explain it briefly: https://xdebug.org/docs/remote

In short, Eclipse (or PHPStorm/Netbeans) is just a client. They internally communicate via DBGp protocol. Normally is classing ping/pong messages in XML: https://xdebug.org/docs/dbgp
1. Session is started by:
1.1. URL generated by IDE, in this way xdebug connect with "idekey". This allow any IDE to verify if debugger connection os valid and can simply ignore it
1.2. Via JIT, if session is initiated outside IDE, it can accept any DEBUG session. Eclipse by default accept all from localhost
2. Port 9000 and listen address have to be configured on both sides. By default is localhost:9000, but if you using for example docker have to be relaxed. In this case I suggest xdebug.remote_connect_back + eclipse allow non-local sessions
3. During initialisation process, ide can tell xdebug to stop on first line (see also HTTP HELO / EHLO) : https://xdebug.org/docs/dbgp#initiating-a-debugging-session
4. Same initialisation process take initially list of breakpoints
5. Later create/delete break point always send message to debugger (if session is active)


Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1827315 is a reply to message #1827228] Wed, 13 May 2020 00:07 Go to previous messageGo to next message
Bernd Wechner is currently offline Bernd WechnerFriend
Messages: 14
Registered: May 2020
Junior Member
Thanks heaps! I had ironically read much of that spec before I dropped back in here just now.

In a nutshell if I understand well:


  1. IDE listens on port 9000
  2. Debugger opens a TCP connection on port 9000 (two way comms)
  3. Debgugger knows toopen that connection either by virtue of a GET param passed in the request or if Xdebug helper is turned on in the browser.


I think that's the summary. Key thing being that IDE listens, Debugger opens connection on port and the comms are two way over that connection thereafter.

Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1832826 is a reply to message #1827178] Fri, 25 September 2020 18:06 Go to previous messageGo to next message
bansalrehana bansalrehana is currently offline bansalrehana bansalrehanaFriend
Messages: 2
Registered: September 2020
Junior Member
I am happy of course to run the "php -S" server, though if I can configure it to start this server automatically what a nice slick boon. So I looked for External Tools as suggested by find only the attached. Namely a dialog that offers no configuration at all alas. What am I missing there?


Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1832986 is a reply to message #1832826] Wed, 30 September 2020 12:07 Go to previous messageGo to next message
Bernd Wechner is currently offline Bernd WechnerFriend
Messages: 14
Registered: May 2020
Junior Member
Guess it depends on what version of Eclipse. But I have the latest and I see it on my toolbar as per attached image. I admit it's not easy to find, and I wish it were clearer, but hey, there it is.

Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1833338 is a reply to message #1832986] Fri, 09 October 2020 11:40 Go to previous messageGo to next message
Mark Smith is currently offline Mark SmithFriend
Messages: 82
Registered: September 2020
Member
Check this article
https://www.eclipse.org/pdt/help/html/debugging_a_php_web_page.htm
Re: How to Debug with Eclipse and PDT, specifically how to use the Built-in Server [message #1833677 is a reply to message #1833338] Wed, 21 October 2020 08:40 Go to previous message
bansalrehana bansalrehana is currently offline bansalrehana bansalrehanaFriend
Messages: 2
Registered: September 2020
Junior Member
Thanks for it

Previous Topic:Can I use bootstrap and PHP together?
Next Topic:[xdebug] Change value in "variables" pane get wrong result
Goto Forum:
  


Current Time: Tue Apr 16 14:37:16 GMT 2024

Powered by FUDForum. Page generated in 0.31653 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top