-   Linux - Software (
-   -   Problems setting up XMLRPC with Apache and PHP (

eikeland 04-05-2006 08:59 PM

Problems setting up XMLRPC with Apache and PHP
I am new to XMLRPC, and I am having some problems.
I have a client script (rpctest.html)
<title>XML-RPC PHP Demo</title>
<h1>XML-RPC PHP Demo</h1>


// Make an object to represent our server.
$server = new xmlrpc_client('sample.php',
'', 9990);
echo "server=".$server;
echo "<br>";
echo "a";
echo "<br>";

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() . ": " .
} 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>";

, that calls a function in a xmlrpc server program (sample.php).
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

core library version xmlrpc-epi v. 0.51
php extension version 0.51
author Dan Libby
open sourced by

I have also downloaded and 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:
server=Object id #1

message=Object id #2
Calling sumAndDifference

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.

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?

All times are GMT -5. The time now is 12:28 AM.