Skip to main content

Tips to make XML-RPC debugging easier

Senior Developer
Mar 05, 2009

In the past few days, I wrote a frontend for an XML-RPC service (I needed both the server and the client part). That was my first meeting with XML-RPC, so I had to debug a lot. However, since I'm pretty familiar with UNIX systems, I found some tools and techniques, which helped me a lot. I wanted to see every bit which goes in and out, to completely understand the process.

1.) netcat
This is a very small but powerful little tool. It can work both client and server mode. In server mode, it outputs every traffic to stdout, in client mode, you can 'talk' with the server from stdin (and you can also use the redirection operators).
The usage is pretty easy:
client mode:
$ netcat hostname port
server mode:
$ netcat -l -p port hostname
It is a real swiss army knife to debug clients and servers.

2.) curl
If you have to work with HTTP POST, then you may find the netcat a bit unconfortable. With curl, it is very easy to perform advanced HTTP operations (such as authenticating), without typing HTTP headers.
I found it pretty useful in posting data to my Drupal XML-RPC server. The trick is easy:

  1. save the post content to a text file
  2. $ curl -d @filename http://localhost/~myusername/mydevdrupalsite/xmlrpc.php

Note, that you can also perform FTP operations with curl. See curl --help.

3.) wireshark
If nothing else helps, the wireshark will help you. It can monitor all network traffic, so make sure that you set at least the "http" filter before you start capturing :) With wireshark, you can see what is going on between the remote server and your machine. It is very useful to look into the raw datastream.

4.) watchdog and var_export
Since the XML-RPC server doesn't display HTML, you can't use var_dump, dprint_r or drupal_set_message to display variables, because if you mess up the strict XML layout, everything can go wrong. In this situation, the watchdog combined with var_export is invaluable. It is very easy to use:

' . var_export($my_var, true) . '


5.) ssh portforward
Because my machine is behind multiple level NAT's, the remote server couldn't send an XML-RPC method call to my Drupal installation. I deployed my Drupal dev site to our test server, and I was in such a fortunate situation that the paths on the test server and on my local macine was exactly the same (absolute path: /home/yorirou/public_html/mydevdrupalsite/, url: /~yorirou/mydevdrupalsite). I was lazy, I didn't want to synchronize the two database. I ran svn checkout on the test server, and the magic:
$ ssh -2 -C -f -N -R 3333:localhost:3306 our.test.server
With a little tweaking in the settings.php, I could use the same database on the test server and on my dev machine.
Note: to make the SSH tunneling work there are two thing what you have to check in your my.cnf:

  1. under the [mysqld] section, this line must be present:
    bind-address =
  2. make sure that the "skip-networking" option is commented out

If you had to change the my.cnf, don't forget to restart your mysql server.

These are the techniques what I developed in the past few days. Do you know anything else what can make it easier to debug the XML-RPC communication? Feel free to post a comment.

Tamás is responsible for the development and design of custom Drupal modules and back-end solutions. He's a self-taught programmer, with his main focus on Drupal, Go and iOS development. Besides programming languages, he's interested in distributed computing, computer graphics, image processing and security. He has a couple of contributed modules on, and he completed the Summer of Code at Drupal in 2010 and 2011. His bigger projects at Pronovix include participating in Drupal Gardens development, helping to create sites for Warner Music Group, Pfizer and Florida Hospitals. He did performance optimizations on Qatarliving. He's one of the main contributors to the Brightcove module used by large Drupal sites worldwide.


Articles on devportals, DX and API docs, event recaps, webinars, and more. Sign up to be up to date with the latest trends and best practices.