How to debug a web service written in PHP?

僤鯓⒐⒋嵵緔 提交于 2019-12-08 08:19:11

问题


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?


回答1:


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('1@127.0.0.1');

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




回答2:


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));



回答3:


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.




回答4:


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.




回答5:


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



回答6:


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



来源:https://stackoverflow.com/questions/2465570/how-to-debug-a-web-service-written-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!