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

| A Simple Request |

Now, while all this futzing about with values is very amusing, it begs the questions: what use are these XML_RPC_Value() objects anyway?

To answer that question, you need to meet two other objects in the XML_RPC pantheon: the XML_RPC_Message() object, and the XML_RPC_Response() object. The XML_RPC_Message() object represents a procedure invocation by the client. When initializing this object, the object constructor must be passed two arguments: the name of the remote procedure, and the arguments to it (as an array of XML_RPC_Value() objects). Take a look at this next script, which illustrates by creating a message packet invoking the procedure setYear(2004):


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

// create value
$value = new XML_RPC_Value("2004", "int");

// create message packet
$msg = new XML_RPC_Message("setYear", array($value));

// encode into XML-RPC-compliant format
echo $msg->serialize();
?>


Here's the output:

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
<?xml version="1.0"?>
<methodCall>
<methodName>setYear</methodName>
<params>
<param>
<value><int>2004</int></value>
</param>
</params>
</methodCall>
').'
'

Typically, the XML_RPC_Message() object is used at the client end of the connection, to create and encode an XML-RPC request. The corresponding server response is represented by a second object, the XML_RPC_Response() object, which is illustrated in the listing below:


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

// create value
$value = new XML_RPC_Value("-1", "int");

// create response packet
$resp = new XML_RPC_Response($value);

// encode into XML-RPC-compliant format
echo $resp->serialize();
?>


In this case, the object constructor is passed the return value of the procedure, again as an XML_RPC_Value() object. Here's the output:

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value><int>-1</int></value>
</param>
</params>
</methodResponse>
').'
'

The answer to the question posed at the top of this page should now be self-evident. As the two examples above illustrate, XML_RPC_Value() objects are a crucial part of the client-server transaction, because procedure arguments and return values are encoded as XML_RPC_Value() objects by the client and server respectively. Encapsulating data (and data types) in XML help the agents at either end of the connection to transfer data back and forth without affecting its integrity.


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-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback