Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using XDebug to trace a PHP web service page

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

like image 693
Traveling Tech Guy Avatar asked Jan 11 '10 22:01

Traveling Tech Guy


2 Answers

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.

like image 192
janpio Avatar answered Oct 09 '22 18:10

janpio


Here is tip on how to trigger Xdebugger client from Curl without browser:

1- From command line:

curl -H "Cookie: XDEBUG_SESSION=1" http://YOUR-SITE.com/your-script.php

2- From PHP

<?php 
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, 'http://YOUR-SITE.com/your-script.php');
curl_setopt ($ch, CURLOPT_COOKIE, 'XDEBUG_SESSION=1');
curl_exec ($ch);
?>

So it doesn't matter if you attach "XDEBUG_SESSION=1" to CURL URL, but what is necessary is to send a proper cookie together with request.

like image 21
Gleb Esman Avatar answered Oct 09 '22 18:10

Gleb Esman