Then, you send your request by calling the server method as it was a local
method of the $client object.

<?php$result = $client->info('XML_RPC2');?>

This single line will encode a XMLRPC client request for the package.info() (prefix + method name)
method with a single argument (the string 'XML_RPC2'), will send the request over HTTP to the
server and will decode the response into PHP native types. With a single line !

Of course, to catch server errors, you have to add a few lines around you client call like for example :

The options array

This array is completely optional but really usefull. The following keys
are available :

Options available keys

Option

Data Type

Default Value

Description

prefix

string

''

Prefix added before XMLRPC called method name

proxy

string

''

Proxy used for the HTTP request (default : no proxy)

debug

boolean

FALSE

Debug mode ?

encoding

string

''

Encoding of the request 'utf-8', 'iso-8859-1' (for now, only these two ones are officialy supported)

uglyStructHack

boolean

TRUE

ugly hack to circumvent a XMLRPCEXT bug/feature , see
this PHP bug
for more details. The only (reasonable) counterpart of this hack is
that you can't use structs with a key beginning with the string
'xml_rpc2_ugly_struct_hack_' as arguments of the called method.

Making the XML_RPC2_Client object

It's really easy to make the XML_RPC2_Client object. Use the following syntax :

Be careful, XMLRPC spec allows some remote method names with some special characters like "." or "/"... which are
not available as PHP method names. To deal with them, you have to fix a prefix in a the options array. For example :

// We call the foo.bar() method because of the prefix 'foo.' fixed in $options array$result = $client->bar();?>

In most cases, XML_RPC2 transforms automatically PHP native types into XMLRPC
types (as described in the SPEC) for the request. In most cases too, XML_RPC2
transforms the XML server response into PHP native types too. Yet, there are
two exceptions : 'dateTime.iso8601' and 'base64' which doesn't really exist in PHP.

To manipulate explicitely these two types, you have to use special objects. Let's see a
complete example :

<?php

// Classic usagerequire_once 'XML/RPC2/Client.php';

// To manipulate these types, we need to include this file toorequire_once 'XML/RPC2/Value.php';

// To get a 'dateTime.iso8601' object, you have first to set a string with an iso8601 encoded date :$tmp = "20060116T19:14:03";

// To transform these objects into PHP native types, you have to use public properties of// these objects as follow :var_dump($result_datetime->scalar); // will return string(17) "20060116T19:14:03"var_dump($result_datetime->xmlrpc_type); // will return string(8) "datetime"var_dump($result_datetime->timestamp); // will return int(1137435243)var_dump($result_base64->scalar); // will return string(6) "foobar"var_dump($result_base64->xmlrpc_type); // will return string(6) "base64"

User Notes:

Sorry if this is obvious, but I didn't see it in the docs anywhere (if it exists, perhaps it should be more prominent); if the service you're connecting to requires HTTP auth, there isn't a method to set your login credentials; it must be encoded into the URL, e.g., http://user:pass@host.domain.com/path.