LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 04-05-2006, 08:59 PM   #1
eikeland
Member
 
Registered: Nov 2004
Location: Newport, RI, USA
Distribution: Mandriva 2006
Posts: 125

Rep: Reputation: 15
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)
<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!

Last edited by eikeland; 04-05-2006 at 09:00 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP xmlrpc problem. Jim44 Programming 0 02-20-2006 12:14 PM
Setting up PHP with Apache D4ve G Suse/Novell 8 06-27-2005 12:20 PM
Setting up apache with php and mysql meander Linux - Networking 6 01-26-2005 05:10 AM
apache setting for php tej Linux - Software 2 09-20-2004 08:17 AM
Help Setting Up PHP On Apache AFI_Flame Linux - Networking 3 06-28-2004 01:44 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration