Motivation: For a side project I am working on, I wanted to be able to send a trackback to WordPress blogs (or any blog with an XMLRPC endpoint), using PHP. Simple enough.
Methodology: I had a few different options. I could have manually made a POST request to the endpoint, hand-coding the XML (this brute force method). Or I could stand on the shoulders of giants and leverage the power of open-source libraries. I chose the latter, in keeping with my new guiding principle of pursuing beauty, truth and goodness.
To brush up on how an XMLRPC pingback works, from a 30,000 foot level, I checked out the Pingback 1.0 Specification. As far as the libraries, I settled on phpxmlrpc. First, the documentation existed and second, it was straightforward. According to the documentation, the process goes like this:
- Create an xmlrpc client
- Set the debug level you think you need (optional)
- Create a new message
- Send the message
- Parse the response
Implementation: Again, this isn’t rocket science, but here’s what I did. Suggestions and critiques are welcome.
A couple of notes. On line 3, “pingback.ping” is the XMLRPC API method that handles pingbacks. Also, the order of the sites you send to the call would be your site, and the site you’re pinging. I switched this order around the first time and got some interesting error messages.