I am new to XMLRPC, and I am having some problems.
I have a client script (rpctest.html)
<html>
<head>
<title>XML-RPC PHP Demo</title>
</head>
<body>
<h1>XML-RPC PHP Demo</h1>
<?php
include("/var/www/html/xmlrpc.inc");
// Make an object to represent our server.
$server = new xmlrpc_client('sample.php',
'192.168.1.3', 9990);
echo "server=".$server;
echo "<br>";
echo "a";
echo "<br>";
$server->setDebug(1);
echo "b";
echo "<br>";
// Send a message to the server.
echo "<br>";
$message = new xmlrpcmsg('messagetest', array(new xmlrpcval(5, 'int'),
new xmlrpcval(3, 'int')));
echo "c";
echo "<br>";
echo "message=".$message;
echo "<br>";
echo "Calling sumAndDifference";
$result = $server->send($message);
echo "After sumAndDifference";
echo $result;
echo "<br>";
echo "d";
echo "<br>";
// Process the response.
if (!$result) {
echo "e";
echo "<br>";
print "<p>Could not connect to HTTP server.</p>";
} elseif ($result->faultCode()) {
echo "ERROR";
print "<p>XML-RPC Fault #" . $result->faultCode() . ": " .
$result->faultString();
} else {
echo "NO ERROR";
$struct = $result->value();
$sumval = $struct->structmem('sum');
$sum = $sumval->scalarval();
$differenceval = $struct->structmem('difference');
$difference = $differenceval->scalarval();
print "<p>Sum: " . htmlentities($sum) .", Difference: " . htmlentities($difference) . "</p>";
}
?>
</body></html>
, that calls a function in a xmlrpc server program (sample.php).
<?php
include("/var/www/html/xmlrpc.inc");
include("/var/www/html/xmlrpcs.inc");
echo "Before sumAndDifference function in sample.";
function sumAndDifference ($params) {
echo "In sumAndDifference function.";
// Parse our parameters.
$xval = $params->getParam(0);
$x = $xval->scalarval();
$yval = $params->getParam(1);
$y = $yval->scalarval();
echo "x=".$x;
echo "y=".$y;
// Build our response.
$struct = array('sum' => new xmlrpcval($x + $y, 'int'),'difference' => new xmlrpcval($x - $y, 'int'));
return new xmlrpcresp(new xmlrpcval($struct, 'struct'));
}
echo "After function.";
// Declare our signature and provide some documentation.
// (The PHP server supports remote introspection. Nifty!)
$sumAndDifference_sig = array(array('struct', 'int', 'int'));
$sumAndDifference_doc = 'Add and subtract two numbers';
new xmlrpc_server(array('messagetest' =>array('function' => 'sumAndDifference','signature' => $sumAndDifference_sig,'docstring' => $sumAndDifference_doc)));
echo "<br>";
echo "After bind";
echo "<br>";
?>
This is my setup (part of phpinfo()):
Apache/2.0.54 (Mandriva Linux/PREFORK-13mdk)
X-Powered-By PHP/5.0.4
xmlrpc
core library version xmlrpc-epi v. 0.51
php extension version 0.51
author Dan Libby
homepage http://xmlrpc-epi.sourceforge.net
open sourced by Epinions.com
I have also downloaded xmlrpc.inc and xmlrpcs.inc and placed them in the default Apache directory (/var/www/html). I am not sure if this is even necessary since php has built in support for xmlrpc since php4.1
When I open rpctest.php, I don't get a response back from the function since it is not called in the sample.php server program. I don't get any errors either. This is the output I see in the browser:
XML-RPC PHP Demo
server=Object id #1
a
b
c
message=Object id #2
Calling sumAndDifference
---GOT---
HTTP/1.1 200 OK
Date: Wed, 05 Apr 2006 23:33:54 GMT
Server: Apache/2.0.54 (Mandriva Linux/PREFORK-13mdk)
X-Powered-By: PHP/5.0.4
Content-Length: 58
Connection: close
Content-Type: text/html
Before sumAndDifference function in sample.After function.
---END---
HEADER: date: Wed, 05 Apr 2006 23:33:54 GMT
HEADER: server: Apache/2.0.54 (Mandriva Linux/PREFORK-13mdk)
HEADER: x-powered-by: PHP/5.0.4
HEADER: content-length: 58
HEADER: connection: close
HEADER: content-type: text/html
Any suggestions what I need to do to make this work?
Thanks!