#native_company# #native_desc#
#native_cta#

WDDX Functions in PHP Page 7

By Jess M. Castagnetto
on July 30, 2000

The Data Consumer (The WDDX Client)

This script will invoke the WDDX packet generating script using an HTTP call
(using the file function,
then deserializes the returned packet (we use the first line in the returned
array,
because the packet is sent back as a continuous stream).
wddx_consumer.php3

<?php

<HTML>

<
HEAD>

<
TITLE>WDDX_CONSUMER.PHP3</TITLE>

</
HEAD>

<
BODY BGCOLOR="white">

<?
php

/*

 * Script that "uses" the WDDX packet generated by

 * wddx_generator.php3

 * Jesus M. Castagnetto, 1999-2000

 */

// get data as a WDDX packet

$url_gen "http://generator.server.com/wddx/wddx_generator.php3";

$packet_in implode("",file($url_gen));

// deserialize the values

$values wddx_deserialize($packet_in);

?>



The variable $values will contain an associative array with keys
corresponding to the names of the variables serialized by the WDDX generating
script (in this example: “bins” and “stats”). We assign these variables (in
themselves arrays), and then process them. In this example, we just display
them in a nice table.

<?php

// extract the bins and stats arrays

$bins $values["bins"];

$stats $values["stats"];

// print a table of histogram bins and statistics.

echo "<TABLE><TR><TH>Histogram bins</TH><TH>Statistics</TH></TR>";

echo 
"<TR VALIGN='top'><TD>";

echo 
"<TABLE BORDER><TR><TH>Bin value</TH><TH>Count</TH></TR>";

while (list(
$k,$v) = each ($bins)) {

    echo 
"<TR><TD ALIGN='center'>".sprintf("%.3f",$k)."</TD><TD>".$v."</TD></TR>n";

}

echo 
"</TABLE>n";

echo 
"</TD><TD>";

echo 
"<TABLE>";

while (list(
$k,$v) = each ($stats)) {

    echo 
"<TR><TD ALIGN='right'>".$k." = </TD><TD>".sprintf("%.3f",$v)."</TD></TR>n";

}

echo 
"</TABLE>n";

echo 
"</TD></TR></TABLE>";

?>



The output of the script above will then be:
Histogram Bins and Stats
This shows how easy it is to create scripts that can serve WDDX packets to
remote applications. These remote applications can be another PHP script
(as in the example), or
perhaps a Java servlet or application, or a Python or Perl script
that understands WDDX packets.
This type of
application to application communication is the backbone of, for example, EDI
systems (Electronic Data Interchange) which are widely uses in business to
business transactions, although the EDI specs do not make use of XML, yet.

1
|
2
|
3
|
4
|
5
|
6
|
7
|
8