Miscellaneous

  Home arrow Miscellaneous arrow Page 4 - Remote Procedure Calls with PEAR::XML-...
MISCELLANEOUS

Remote Procedure Calls with PEAR::XML-RPC
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2004-01-29

    Table of Contents:
  • Remote Procedure Calls with PEAR::XML-RPC
  • The Example Script
  • An XML_RPC Exchange
  • Client Rewritten Example
  • Client Sending
  • Client Receiving
  • Server Rewritten Example
  • Distributed Function Requirements
  • Inside the Function
  • Map and Send
  • The Output
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    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-&gt;send($message);

    echo 
    "&lt;p&gt;&lt;b&gt;Function Call:&lt;/b&gt; $function($first, $last)&lt;/p&gt;";
    echo 
    "&lt;p&gt;&lt;b&gt;Sent XML Message:&lt;/b&gt;";
    echo 
    "&lt;pre&gt;" htmlentities($message-&gt;serialize()). "&lt;/pre&gt;&lt;/p&gt;";

    $value $result-&gt;value();
    $number $value-&gt;scalarval();

    echo 
    "&lt;p&gt;&lt;b&gt;Return Value:&lt;/b&gt; $number &lt;/p&gt;";
    echo 
    "&lt;p&gt;&lt;b&gt;Received XML Message:&lt;/b&gt;";
    echo 
    "&lt;pre&gt;" htmlentities($result-&gt;serialize()) . "&lt;/pre&gt;&lt;/p&gt;";

    echo 
    "&lt;p&gt;$first $last's name is $number letters long.&lt;/p&gt;";
    ?>

    More Miscellaneous Articles
    More By bluephoenix

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap