Remote Procedure Calls with PEAR::XML-RPC - Server Rewritten Example
(Page 7 of 12 )
Now it's time to explore a server component capable of handling the XML-RPC message. PEAR::XML-RPC also provides us an easy way to do this:
<?php require_once("XML/RPC/Server.php");
$getnamelength_sig = array(array("int", "string", "string")); $getnamelength_doc = "Accepts two string parameters, joins them and then returns the length of the resulting string.";
function getnamelength($msg) {
$name1 = $msg->getParam(0); $name2 = $msg->getParam(1);
$length = strlen($name1->scalarval() . $name2->scalarval());
$result = new XML_RPC_Value( $length, "int");
return new XML_RPC_Response($result); }
$map = array("getNameLength" => array("function" => "getnamelength", "signature" => $getnamelength_sig, "docstring" => $getnamelength_doc)); new XML_RPC_Server($map); |
The XML/RPC/Server.php class is included from the PEAR library. The server class imports the functionality of XML/RPC.php, so you only need just the one include.
<?php require_once("XML/RPC/Server.php"); ?> |
Next: Distributed Function Requirements >>
More Miscellaneous Articles
More By bluephoenix