Remote Procedure Calls with PEAR::XML-RPC - Client Rewritten Example
(Page 4 of 12 )
An XML-RPC package is provided by the default PEAR installation, which we can take advantage of to ease the creation and processing of XML-RPC calls. For more information on PEAR you may want to view one of my previous tutorials entitled Introduction to PEAR or visit the PEAR website at http://pear.php.net.
Our example script has now been rewritten to make an XML-RPC call to getNameLength using the PEAR::XML-RPC class. Also, the output is now more verbose so that we see the XML data that's transferred.
<?php require_once("XML/RPC.php");
$first = "George"; $last = "Washington";
$function = "getNameLength";
$p1 = new XML_RPC_Value($first, "string"); $p2 = new XML_RPC_Value($last, "string"); $params = array($p1, $p2);
$message = new XML_RPC_Message($function, $params);
$client = new XML_RPC_Client("/RPC2.php", "localhost", 80); $result = $client->send($message);
echo "<p><b>Function Call:</b> $function($first, $last)</p>"; echo "<p><b>Sent XML Message:</b>"; echo "<pre>" . htmlentities($message->serialize()). "</pre></p>";
$value = $result->value(); $number = $value->scalarval();
echo "<p><b>Return Value:</b> $number </p>"; echo "<p><b>Received XML Message:</b>"; echo "<pre>" . htmlentities($result->serialize()) . "</pre></p>";
echo "<p>$first $last's name is $number letters long.</p>"; ?> |
Next: Client Sending >>
More Miscellaneous Articles
More By bluephoenix