Using XDebug to trace a PHP web service page Using XDebug to trace a PHP web service page curl curl

Using XDebug to trace a PHP web service page


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.


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.


I know this is a pretty old thread, but I thought I'd post my experience for others that may come across it, like I did, with the same problem. What I discovered is that, if you are debugging remotely (which I always do), there are a couple settings you have to change in php.ini to make this work. Here are the ones that worked for me:

xdebug.remote_connect_back = falsexdebug.remote_host = {client host name or IP}

The first setting is normally "true," and tells xdebug to look for the client at the same IP address where the HTTP request originated. In this case however, the request is coming from the server, so that won't work. Instead you must use the second setting to tell xdebug where to find the client. Hope this helps save somebody a little time!