Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function split() is deprecated in /home3/vvaswani/public_html/community/columns/trog/article.php on line 101

Deprecated: Function eregi_replace() is deprecated in /home3/vvaswani/sql.php on line 301

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home3/vvaswani/public_html/community/columns/trog/article.php on line 107

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home3/vvaswani/public_html/community/columns/trog/article.php on line 109

Deprecated: Function ereg_replace() is deprecated in /home3/vvaswani/public_html/community/columns/trog/article.php on line 124

Deprecated: Function ereg_replace() is deprecated in /home3/vvaswani/public_html/community/columns/trog/article.php on line 125

Deprecated: Function split() is deprecated in /home3/vvaswani/public_html/community/columns/trog/article.php on line 127

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174
The Melonfire Community - Trog
Logo         Community
  Trog
Services
The Company
Community
Columns
Your Account
Contact Us
 
 
Performing Remote Procedure Calls With PEAR XML_RPC
Learn to harness the power of XML-RPC in your PHP scripts

| Service With A Smile |

With the basics out of the way, let's now turn our attention to the meat of the XML_RPC package - the Server and Client objects. Consider the following listing, which demonstrates the process of creating an XML-RPC server:


<?php
// include server class
include ('XML/Server.php');

// create server
// set up dispatch map
$server = new XML_RPC_Server(array("whoAmI" => array("function" => "phpWhoAmI")));
?>


With the PEAR XML_RPC class, creating an XML-RPC server is pretty simple - all you need to do is initialize an object of the XML_RPC_Server() class, and pass the object constructor what geeks call a dispatch map. Essentially, a dispatch map maps the server's "public" XML-RPC procedures to "private" PHP functions; every time an XML-RPC procedure is called by a client, the server consults the dispatch map to see which PHP function it should invoke to handle the call.

In the example above, the XML-RPC server exposes a single procedure - whoAmI() - which is internally mapped to the phpWhoAmI() function. This PHP function is responsible for parsing the XML-RPC request packet, extracting the procedure arguments from it, performing its calculations, and encoding the return value into a response packet suitable for transmission to the server. Let's take a closer look, to see how all these tasks are accomplished:


<?php
// include server class
include ('XML/Server.php');

// create server
// set up dispatch map
$server = new XML_RPC_Server(array("whoAmI" => array("function" => "phpWhoAmI")));

// function to parse arguments and return them to
// caller in different format
function phpWhoAmI($params)
{
   $name = $params->getParam(0);
   $species = $params->getParam(1);
   $age = $params->getParam(2);

   $response = "I am " . $name->scalarval() . ", a " . $age->scalarval() . "-year old " . $species->scalarval();

   // return response to client
   return new XML_RPC_Response(new XML_RPC_Value($response, "string"));
}
?>


From the above, it is clear that three arguments are required by the phpWhoAmI() function - a name, a species type, and an age. These three arguments are extracted as XML_RPC_Value() objects from the request packet via the getParam() method, and their values are retrieved via each object's scalarval() method. Once retrieved, the arguments are interpolated into a longer string, which is then repackaged as an XML_RPC_Response() object, and returned to the caller.


How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!


previous page more like this  print this article  next page
 
Search...
 
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
more...
 
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
more...
 
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
more...
 
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
more...
 
In cut!...
American Chai
The Core
Possession
more...
 
Find out how you can use this article on your own Web site!


Copyright © 1998-
Strict Standards: mktime(): You should be using the time() function instead in /home3/vvaswani/public_html/community/columns/trog/article.php on line 731
2018 Melonfire. All rights reserved
Terms and Conditions | Feedback