Chapter 5. Class documentation

Table of Contents
xmlrpc_client
xmlrpcmsg
xmlrpcresp
xmlrpcval
xmlrpc_server

xmlrpc_client

This is the basic class used to represent a client of an XML-RPC server.

Creation

The constructor has the following syntax:

$client=new xmlrpc_client($server_path, $server_hostname, $server_port);

Here's an example client set up to query Userland's XML-RPC server at betty.userland.com:

$client=new xmlrpc_client("/RPC2", "betty.userland.com", 80);

The server_port parameter is optional, and if omitted will default to 80.

Methods

This class supports the following methods.

send

This method takes the form:

$response=$client->send($xmlrpc_message, $timeout);

Where $xmlrpc_message is an instance of xmlrpcmsg (see xmlrpcmsg), and $response is an instance of xmlrpcresp (see xmlrpcresp).

The $timeout is optional, and will be set to 0 (wait forever) if omitted. This timeout value is passed to fsockopen().

If the value of $response is 0 rather than an xmlrpcresp object, then this signifies an I/O error has occured. You can find out what the I/O error was from the values $client->errno and $client->errstring.

In addition to low-level errors, the XML-RPC server you were querying may return an error in the xmlrpcresp object. See xmlrpcresp for details of how to handle these errors.

setCredentials

$client->setCredentials($username, $password);

This method sets the username and password for authorizing the client to a server. With the default (HTTP) transport, this information is used for HTTP Basic authorization.

setDebug

$client->setDebug($debugOn);

$debugOn is either 0 or 1 depending on whether you require the client to print debugging information to the browser. The default is not to output this information.

The debugging information includes the raw data returned from the XML-RPC server it was querying, and the PHP value the client attempts to create to represent the value returned by the server. This option can be very useful when debugging servers as it allows you to see exactly what the server returns.