In this final part of a four-part series that explores PEAR, you will learn about the XML-RPC protocol, which is very useful when it comes to building web services. It is surprisingly simple, both to install and to use. You'll learn how to create a client and more.
XML-RPC is an XML-based protocol which allows various languages to inter-operate in a standards-based manner. The protocol encapsulates the data of method calls in a simple XML format which can then be easily transmitted over HTTP. Many popular sites provide a web service which uses this protocol. The ability to consume these services, or provide APIs of your own, will give you many options when seeking to have your site work with others.
XML-RPC is often considered the predecessor to SOAP and originated in 1998. It was originally created by Dave Winer of Userland, with the help of Microsoft. While many organizations have moved to provide SOAP or other interfaces, quite a few have maintained XML-RPC, as it is often seen as a nice, light weight, and simple solution.
The specification for XML-RPC is very minimal, detailing only a handful of data types and a simple syntax for calling methods. The included data types are explained in this table:
boolean: TRUE, FALSE
string: "Simple String"
date('c') (added in PHP5)
'pi' => 3.14,
'The Answer' => 42
As you can see, the XML-RPC protocol allows a variety of simple and complex data structures to be converted into a simple XML syntax. This simplicity allows a variety of languages and platforms to easily inter-operate, sending simple XML snippets back and forth and translating them easily into native data structures.
PEAR provides a convenient package for accessing and creating XML-RPC services, XML_RPC2. To use the following examples, you'll need to install the package.
> sudo pear install XML_RPC2
downloading XML_RPC2-1.0.2.tgz ...
Starting to download XML_RPC2-1.0.2.tgz (49,025 bytes)
.............done: 49,025 bytes
install ok: channel://pear.php.net/XML_RPC2-1.0.2
Assuming you get the "install ok" message, you're ready to go! The XML_RPC2 files have been installed in your directory, and can be included in your applications.