Tuesday, February 15. 2005
Today I
released the first public beta of XML-RPCi -- an improved XML-RPC extension for PHP 5+. Built upon the libxml2 library it supports object overloading and automatic fault handling as interfaces for XML-RPC requests.
For instance:
<?php
// Calling methods from the 'package' namespace
$package = new XMLRPC("http://pear.php.net/xmlrpc.php", "package.");
try {
$package->info("DB");
} catch (XMLRPC_Fault $fault) {
var_dump($fault);
}
?>
The basic use is as follows:
new XMLRPC($xml_rpc_url [, $optional_calling_prefix]);
Where $optional_calling_prefix is used for situations where the XML-RPC method being called contains a namespace prefix which can't be easily called from PHP. For instance, to call the 'package.info()' RPC method you can't do:
$rpc->package.info("DB");
instead you would specify the string "package." for $optional_calling_prefix and then use the method directly:
$rpc->info("DB");
Although this limits the instance of a class to calling a particular "namespace" of RPC calls, you can also call methods in other namespaces using the '__call' method:
$rpc->__call("package.info", "DB");
In the event of an error from the XML-RPC server (a fault) or a malformed response a XMLRPC_Fault will be thrown.
Feedback welcome of course, and please report any bugs to me. As the extension matures I plan on adding support for creating XML-RPC servers and backward compatiable functions from the old ext/xmlrpc extension.