nightcoder
nightcoder

Reputation: 13509

How to debug a web service written in PHP?

I've got a nice question here :)

I need to debug my web service written in PHP. Its client is written in C#.
After a couple of days of searching I realized this is not an easy task. At least it seems nobody knows the right solution.

What is the problem in, actually?
We have 2 popular PHP debugging libraries : PHP Debugger from NuSphere and XDebug extension.
The problem is they both are controlled from URL query string or with the help of cookies. For example, to enable debugging with PHP Debugger you need to add ?DBGSESSID=xxx parameter to your URL or to have DBGSESSID cookie.
But when your web service is called from the external client, the client doesn't have a cookie and doesn't add DBGSESSID url parameter. So how can we debug in this situation?

PS. I don't want to write to log files, see request and response headers/data or something like this. I want normal step-by-step debugging and breakpoints.

Anyone?

Upvotes: 1

Views: 7749

Answers (6)

Michael B.
Michael B.

Reputation: 3430

I use the plugin Poster to help debug my php Webservice

Edit :

Found a better tool to debug web service : Advanced REST client Application

It's a Chrome Plugin, works great to test all kind of web services that use REST

Upvotes: 0

nightcoder
nightcoder

Reputation: 13509

Well, I am answering to myself. If we use PHPEd & DBG, then we can use the magic function DebugBreak().

Make sure PHPEd & PHP DBG Listenere are running, write

DebugBreak('[email protected]');

anywhere in your werbservice's code, make a call from the client, and voila! - you are in PHPEd on that line in debugging mode!

Upvotes: 5

Dathan
Dathan

Reputation: 7446

I seem to remember that you can configure NuSphere's product to automatically attempt to connect to the debug listener with or without the DBGSESSID parameter (in query string or cookie). I'm not positive if that's the case, though. However, you can get the effect you're looking for by doing the following. It may be a little more manually intensive than you're hoping for.

  1. Setup some sort of HTTP query/response listener.
  2. Perform desired access against web service from client.
  3. Manually re-issue those requests, appending the appropriate DBGSESSID

For a little more initial setup, but lower friction debugging later:

  1. Configure your client to access an alternate URL.
  2. Setup a proxy to listen on that URL (for debugging, I've seen Privoxy recommended, though I have no experience with it personally).
  3. Configure the proxy to forward all requests to the real web service, appending an appropriate DBGSESSID parameter or including the cookie

Upvotes: 0

user262976
user262976

Reputation: 2074

you could set xdebug.remote_autostart to 1 to always debug (no request parameter needed). this could be limited to some url with the <Location> or <Files> directive.

Or just log some debug information (using Zend_Log or Pear Log if you want a generic library) using var_export.

quick and dirty way is:

file_put_contents('/tmp/log1.txt',
  var_export(array($_REQUEST, $something), true));

Upvotes: 2

Joe Mastey
Joe Mastey

Reputation: 27119

Try SoapUI to issue requests manually and get the detailed responses. Not sure if you can fake the cookie, but you can control the endpoints, and therefore the URL to an extent.

Upvotes: 0

St. John Johnson
St. John Johnson

Reputation: 6660

You could write data to a log file (meh).

Or output debugging information in response headers (if the client can view them). But as far as using breakpoints, you may be out of luck.

You could also look into connection hijacking on your local computer (something similar to the Firefox AddOn Tamper Data) where you can interrupt the request and add the url parameter.

Upvotes: 0

Related Questions