Intended Audience
Overview
Learning Objectives
Definitions
Background Information
Prerequisites
How the script works
Step 1: Creating the Client
Step 2: Constructing the Request
Step 3: Sending the request to the server
Step 4: Working with server’s response
Working with the xmlrpcval class
The Script
Intended Audience
This tutorial is written for the PHP developer interested in implementing an
XML-RPC client in PHP.
Experience working with PHP classes and an understanding of the HTTP protocol
are assumed.
Overview
This tutorial teaches you, step-by-step, how to build an XML-RPC client in
PHP using the XML-RPC library written by Edd Dumbill. It covers each of the PHP
classes you will be using, and how they fit together to form the final client.
A primer is included to introduce the basics of the XML-RPC specification.
The primer provides enough information to work with the XML-RPC library. If you
want to learn more about the XML-RPC specification see
Learning Objectives
In this tutorial you will:
- Learn the basics of XML-RPC and its underlying technologies and ideas.
- Implement and learn how to build an XML-RPC client in PHP.
- Learn some good practices for handling the data returned from an XML-RPC Server.
Definitions
- XML-RPC Message — XML-RPC messages are the requests and responses sent between server and client. They are similar to regular HTTP calls except the payload is XML.
- CURL — A library written by Daniel Stenberg that allows you to connect to many different types of servers using a variety of protocols. It needs to be compiled into your PHP if you want to use XML-RPC over HTTPS.
- HTTPS — An extension to the HTTP protocol that supports encryption.
Background Information
This section provides a brief introduction to XML-RPC. You can skip this
section if you are ready to start building your client right away.
XML-RPC is not a new technology; rather it is a new way of using existing
technologies. It is simply XML over HTTP. Let’s quickly review each of XML-RPC’s
supporting technologies starting with the tried and true HTTP.
HTTP stands for the Hypertext Transfer Protocol and is protocol of the World
Wide Web. It is lightweight, easy to implement, and it can carry both plain text
and binary data. By using HTTP as the carrier protocol, XML-RPC can be easily
implemented in millions of existing Web servers.
XML stands for eXtensible Markup Language. XML is a language designed for
creating other mark up languages. By using XML to structure the data, XML-RPC
becomes completely platform independent. (Imagine your toaster using XML-RPC to
order more bread through your grocer’s Web site.)
RPC stands for Remote Procedure Call. Every operation in a computer is the
result of a procedure call. RPC takes this a step further by allowing computers
to make procedure calls on other — remote –computers. XML-RPC implements this
idea with XML and HTTP.
XML-RPC has eight data types. They are:
- int
- double
- string
- boolean
- base64
- dateTime.iso8601
- array
- struct
Most of those data types will already be familiar to you if you are an
experienced programmer. (See the XML-RPC specification for the exact definitions
and data ranges of each type.) For our present purposes, knowing the difference
between the two complex types array and struct is enough. The array type is like
an indexed array, whereas the struct type is like an associative array.
// An XML-RPC array type is similar to:
$array = array (‘one’,‘two’,‘three’);
// An XML-RPC struct type is similar to:
$struct = array (
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.