Main Page
 The gatekeeper of reality is
 quantified imagination.

Stay notified when site changes by adding your email address:

Your Email:

Bookmark and Share
Email Notification
Project "PHP XML-RPC Web Services"
The purpose of this project is to show you how to set up and use a simple web service, using PHP, through XML-RPC.

Project Details
Like all of the big B2B (Business to Business) web sites that use web services to pass data back and forth between web sites, you can also use the same type of process when you want to have data passed from one web site to another web site. Luckily, the most challenging part of the whole process has been done by a variety of programmers; in this tutorial the XML-RPC written by Keith Devens will be used.

Let's begin by examining Figure 1 below. Site 1 is a client web site that will request information from Site 2.
Figure 1
Figure 1

Site 1
The webpage on Site 1 which triggers the request for data from Site 2 is "client.php". Within this webpage the function "sendRequest($number, $txt)" actually sends a request using the XML-RPC on Site 1. $number can be any number you may need to pass and $txt can be a string you may need to pass.

Before we go too far, the global variable "$targetsite" is the URL to Site 2 and the global variable "$targetlocation" is the name of the PHP webpage on Site 2 that will accept data requests from Site 1.

In client.php let's perform a request for data from Site 2. Since our function basically formats the data from Site 2 into HTML in this tutorial, we can simply print out what the function returns:
echo sendRequest(0, '');

Site 2
Server.php is called and detects that a request for data has been made from Site 1. But when you look at the code in server.php you'll quickly notice there is hardly anything there (XMLRPC_parse() grabs the incoming data request from Site 1, however, and does pass it along). The actual file that you would need to modify is called "web_methods.php". Specifically, you would want to modify the function "block_getData($query_info)" since this takes the data sent to it (from Site one...the function "sendRequest(0, '')"), performs an action and then returns data via the function XMLRPC_response().

As you can see by examining the function "block_getData($query_info)" three blocks of data is generated to be sent back to Site 1.

Back to Site 1
As you recall, the function "sendRequest(0,'')" sent the data request to Site 2. Site 2 responded and sent back three blocks of data. Upon examination of "sendRequest(0,'')" you'll see the following:
/* Request Successful */
$count = 0;
while (list($key, $val) = each ($response)) {
$output = $output . "<b>ID = </b>" . $response[$count]['id'] . "<br />";
$output = $output . "<b>Field 1 = </b>" . $response[$count]['field1'] . "<br />";
$output = $output . "<b>Field 2 = </b>" . $response[$count]['field2'] . "<br />";
$output = $output . "<b>Field 3 = </b>" . $response[$count]['field3'] . "<br />";
$output = $output . "<b>Field 4 = </b>" . $response[$count]['field4'] . "<br />";
$output = $output . "<b>Field 5 = </b>" . $response[$count]['field5'] . "<br />";
$output = $output . "<b>Field 6 = </b>" . $response[$count]['field6'] . "<br />";
$output = $output . "<b>Field 7 = </b>" . $response[$count]['field7'] . "<br />";
$output = $output . "<b>Field 8 = </b>" . $response[$count]['field8'] . "<br />";
$output = $output . "<b>Field 9 = </b>" . $response[$count]['field9'] . "<br />";
$output = $output . "<b>Field 10 = </b>" . $response[$count]['field10'] . "<br />";
$count = $count + 1;

That code actually takes the data that was returned and places it into HTML to be displayed on the webpage. With that, the simple web service is complete!

Download Complete Example
Download the complete code tutorial here (zip format; 40kb in size) so you can view the code pages in detail as you go through this tutorial webpage.
About Joe