Debugging Web Services

Debugging normal  PHP web applications is pretty straight forward. I use Eclipse but almost all IDEs have some means of setting break points and seeing the value of variables. I know some people put print or log statements in their code but this is much more time consuming than just setting a breakpoint and looking at the variables there, and maybe steping forward to see how the script runs.

I would be interested to hear if others usually use IDEs like Eclipse and debug in this way. I would hate to work without it. I even use it to check a newly written script or one that I have taken over responsibility for. Stepping through the processing can help you spot problems very easily.

Now all that is ok for a simple script or web application, but what about the server end of a web service? Normally the server runs in response to a client call. The client request may be quite complex, so how do you debug the server side?

Well my answer is to log the client request as it is received by the server as follows. Add this code to the very top of your server entry point, then have the client make its request. The server will log the request then carry on to produce a result (or not if there is some bug you want to fix).

To debug the server side, replace the above code with the following.

That’s it!. Now you can debug the server side without needing a client to make a request. The server entry point thinks it is getting a request from a client, but really it is just coming from the log file.

Now all this might seem trivial or obvious, but it took me a while to work this out when I had my first web service server to debug. Suddenly I’m just debugging a stand alone script rather than a server than depends on an external client request.

I would be very interested to see if this is useful to anyone.

 

 

 

 

One thought on “Debugging Web Services

  1. Illana,

    Thanks for your note to my blog (greg.ambrose.id.au). Do you work with Sugar or PHP?

    Regards,
    Greg

Comments are closed.