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 08:30  |
Eclipse User |
|
|
|
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.
- I have no idea what's up with Eclipses PHP Build-in Server? Where is that? How does that even try to work?
- Why won't it break on breakpoints when run my own minimal server? Renders the pages fine, won't break?
- 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 #1827190 is a reply to message #1827187] |
Sat, 09 May 2020 21:37   |
Eclipse User |
|
|
|
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] |
Sat, 09 May 2020 22:10   |
Eclipse User |
|
|
|
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 #1827227 is a reply to message #1827205] |
Mon, 11 May 2020 02:49   |
Eclipse User |
|
|
|
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.
|
|
| | | | | | |
Goto Forum:
Current Time: Tue Apr 15 02:07:32 EDT 2025
Powered by FUDForum. Page generated in 0.07678 seconds
|