XML/RPC/Simple
WARNING
This page is here only for historical purposes :) Nothing here is maintained ! If you search such features, see PEAR/XML/RPC2.
Introduction
In very high level languages like Python, webservices are really easy to use on the client side like on the server side. SOAP or XMLRPC calls are natural like :
client.function('arg1', 'arg2')
No need to encode the arguments in XMLRPC stuff, no need to make a XMLRPC message before sending it. No need to decode the XMLRPC response... It's really easy : you just call a method (like it was local).
In PHP, a client call with PEAR/XML/RPC/Client is complex :
[...]
$params = array(new XML_RPC_Value(1, 'int'));
$msg = new XML_RPC_Message('release.getRecent', $params);
$cli = new XML_RPC_Client('/xmlrpc.php', 'pear.php.net');
$resp = $cli->send($msg);
$val = $resp->value();
$data = XML_RPC_decode($val);
[...]
There is a encoding process, a decoding process. It's really boring when you use a lot of XMLRPC webservices. The server side is as complex.
Main ideas
- Make a PHP5 only class to be able to use __call catchall for automatic proxy creation ;
- Automatic encoding and decoding (XML_RPC stuff has to be completly encapsulated (and hidden)) ;
- DO NOT REINVENT THE WHEEL : classes are only parent classes of XML_RPC_Client and XML_RPC_Server ones.
Examples
Server side
<?php
require_once('XML/RPC/Simple/Server.php');
// Dispatch Map
$dispatchMap = array(
'ping' => array('function' => 'ping'),
'test' => array('function' => 'test')
);
// Classic functions (no XML_RPC stuff here !)
function ping() {
return 'pong';
}
function test($var1, $var2) {
return(array($var, array($var1, $var2)));
}
$xmlrpc = new XML_RPC_Simple_Server($dispatchMap);
?>
Client side
<?php
require_once('XML/RPC/Simple/Client.php');
$client = new XML_RPC_Simple_Client('....../xmlrpc.php', 'host');
if ($client->ping()=='pong') {
print_r($client->test('foo','bar'));
}
?>
Easy, isn't it ?
The result is of course :
Array
(
[0] => foo
[1] => Array
(
[0] => foo
[1] => bar
)
)
So, the automatic encoding/decoding process works well even with complex return type.
Releases
For the moment, there is only an anonymous subversion access. Repository is available at svn://openesub.org/fabien/XML_RPC_Simple.
