Miscellaneous
  Home arrow Miscellaneous arrow Page 5 - Remote Procedure Calls with PEAR::XML-RPC
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS

Remote Procedure Calls with PEAR::XML-RPC
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Remote Procedure Calls with PEAR::XML-RPC - Client Sending


    (Page 5 of 12 )

    We start by requiring the use the PEAR package XML/RPC.php. The $first and $last variables remain unchanged, but we store the name of the remote function as $function. The $number variable will serve the same purpose as before but will appear later in our script.

    <?php
    require_once("XML/RPC.php");

    $first "George";
    $last "Washington";

    $function "getNameLength";
    ?>

    The XML-RPC specification was designed for use by a variety of languages; while PHP is a loosely typed language we are still required to pass the value's type. Valid data types are: int, double, string, boolean, array, struct, dateTime.iso8601 and base64.

    We define each parameter to be passed using XML_RPC_Value that accepts a value and it's type. The $params array simply gathers the resulting objects into an array.

    <?php
      $p1 
    = new XML_RPC_Value($first"string");
      
    $p2 = new XML_RPC_Value($last"string");
      
    $params = array($p1$p2);
    ?>

    An XML message object is constructed by passing the function name and the array of parameters to XML_RPC_Message.

    <?php
      $message 
    = new XML_RPC_Message($function$params);
    ?>

    In order to send the message we must be able to locate the remote server. A connection is established by using XML_RPC_Client and passing the server interface, the remote server's address and the designated port number through which communications will travel. Again, the most common transport mechanism used for RPC is the HTTP protocol and so we use port 80.

    Finally, the message is sent by invoking the send method on the server object. The method accepts the message object and returns an XML response object which we store as $response.

    <?php
    $client 
    = new XML_RPC_Client("/RPC2.php""localhost"80);
    $result $client-&gt;send($message);
    ?>

    The serialize method can be used at any time on either a message or response object to view the data in context of its XML wrappings.

    <?php
      
    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;";
    ?>

    More Miscellaneous Articles
    More By bluephoenix


       · I am Sobhan Palpal_sobhan@hotmail.comenjoy php!!live and let...
       · f
       · kk
     

    MISCELLANEOUS ARTICLES

    - Stopping CSRF Attacks in Your PHP Applicatio...
    - Quick and Dirty AJAX Tutorial
    - Flickr Puzzle Mashup
    - The PAVISE of Security
    - Creating a CAPTCHA with PHP
    - Sending SMS Thru HTTP
    - The Postal Fix - Part 2
    - Adding Mail with Exim
    - The Postal Fix - Part 1
    - Create Your Own Custom API
    - Adding Drop Shadows with PHP
    - Writing a Basic Authentication System in PHP
    - Overlapping Images with GD
    - Using Sockets in PHP
    - Dynamic CSS with PHP






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway