views:

750

answers:

3

I'm using Eclipse and XDebug to develop a PHP application that relies on web services. I have test pages that consume my services in 2 ways: AJAX (using jQuery) and cURL.

I add breakpoints to my service page and launch the debugger. When I call the the service from AJAX, execution stops nicely at the breakpoint, and I get my variables, step-by-step control etc.

But when I call the service using cURL (i.e. from within a PHP page), the breakpoints fail to function. Even if I turn on the "Break at first line" debugger option, I cannot get the execution to stop when using cURL.

Is it a debugger behavior? Do I need to add a hearder to my cURL calls? Alter the URL? Or is it an XDebug limitation?

Thanks for your time and effort, Guy

+1  A: 

When you are debugging the Ajax request, that one is sent by the browser, in the same navigation context as the other (non-Ajax) requests -- which is why it works fine.


The request sent by curl is in another, different, context -- and I'm not sure you can hook the debugger into that... But, maybe...

First of all, here's an information that might prove helpful, quoting the Xdebug's documentation :

Xdebug contains functionality to keep track of a debug session when started through a browser: cookies. This works like this:

  • When the URL variable XDEBUG_SESSION_START=name is appended to an URL Xdebug emits a cookie with the name "XDEBUG_SESSION" and as value the value of the XDEBUG_SESSION_START URL parameter.
  • When there is a GET (or POST) variable XDEBUG_SESSION_START or the XDEBUG_SESSION cookie is set, Xdebug will try to connect to a debugclient.
  • To stop a debug session (and to destroy the cookie) simply add the URL parameter XDEBUG_SESSION_STOP. Xdebug will then no longer try to make a connection to the debugclient.

Maybe it might work if you set that cookie "by hand", sending it allong the curl request...

I suppose you'd first have to get its value, as set by Xdebug at the beginning of the debugging session -- re-using the cookie you have in your browser should be possible, though.

Note : I've never tried this -- if you try, and it works, could you please confirm it worked ?

Pascal MARTIN
Traveling Tech Guy
Oh ;-( Too bad ;-(
Pascal MARTIN
Thanks for trying! :)
Traveling Tech Guy
A: 

I can't comment yet, so I post this as an answer.

Can you debug more than one AJAX request in one session? Was your debug session still running in Eclipse when you tried to debug using cURL?

Description on how it works for me:

  1. Start debug session with a simple debug.php file that contains only a <?php and nothing else. It stops on the first line, you "continue" it and it finishes execution.
  2. Now request the script using cURL (or another browser) adding ?XDEBUG_SESSION_START=ECLIPSE_DBGP to its path (I even think this addition is optional)
  3. Your script should show up in the debug view stopped at the first line

Hope ths helps.

Jan P.
Thanks for trying Jan. Yes, I can debug more than one Ajax call and Yes my debug session is still running in Eclipse. And as you can see below, I've tried adding XDEBUG_SESSION_START=ECLIPSE_DBGP to my cURL call - to no avail.
Traveling Tech Guy
@Traveling Tech Guy: I will try this tomorrow at work. I'm 99% sure this works for me, so we will make it work for you too.
Jan P.
Yep, tried it again and it works. You don't need KEY, XDEBUG_SESSION_START is enough. Then it works in every browser and every way I connect to the server my debug session is running. Have you checked your request log if the cURL request really does the right thing?
Jan P.
A: 

I ran into this same exact issue. I solved it by turning the auto-start feature off in php.ini:

xdebug.remote_autostart = 0

and then adding the API key to the webservice URL that my webservice client calls:

?XDEBUG_SESSION_START=<your API key here>

and I'm not sure if this matters, but I entered the API key into my debugger (MacGDBp). Now the debugger fires up only when the webervice server-side script is called, not when the client is started.

Hope this helps.

matt