Need help with xmlrpc in php
I have downloaded phpxmlrpc from http://phpxmlrpc.sourceforge.net/
I have a folder on my webserver called xmlrpc-test and have a simple test php app created.
<?php
include 'xmlrpc.inc';
include 'xmlrpcs.inc';
function sumAndDifference ($params) {
// Parse our parameters.
$xval = $params->getParam(0);
$x = $xval->scalarval();
$yval = $params->getParam(1);
$y = $yval->scalarval();
// Build our response.
$struct = array('sum' => new xmlrpcval($x + $y, 'int'),
'difference' => new xmlrpcval($x - $y, 'int'));
return new xmlrpcresp(new xmlrpcval($struct, 'struct'));
}
// 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('sample.sumAndDifference' =>
array('function' => 'sumAndDifference',
'signature' => $sumAndDifference_sig,
'docstring' => $sumAndDifference_doc)));
?>
I have loaded the phpxmlrpc debugger, entered the Address:, Port: and Path: but when I press the execute button for List available methods
开发者_StackOverflownothing happens.
Question 1: why does my local debugger not work?
So I went online here http://phpxmlrpc.sourceforge.net/jsxmlrpc/debugger/debugger.html and it seems to work better.
However, when I press the execute button here (after entering my server details) I get the following message.
Fault code: [5] Reason: 'Didn't receive 200 OK from remote server. (send failed)'
I thought this may have meant there was something wrong with my local server and the WAN so I tested the app at http://feedvalidator.org/ and I do in fact get a response.
1. <?xml version="1.0"?>
2. <methodResponse>
3. <fault>
4. <value>
5. <struct><member><name>faultCode</name>
6. <value><int>105</int></value>
7. </member>
8. <member>
9. <name>faultString</name>
10. <value><string>XML error: Invalid document end at line 1, column 1</string></value>
11. </member>
12. </struct>
13. </value>
14. </fault>
15. </methodResponse>
I think this is an error because there is not payload being sent.
Question 2: How do I solve this? How can I get a very simple xmlrpc server working with php?
For posterity, I'll give my input.
First, Your local debugger doesn't work because of silent sabotaging by the security sandbox. The W3C and browser vendors worked out a scheme whereby the browser will silently translate the POST request your debugger is sending to an OPTION request instead. It seems like a real kludge because the browser gives no visible indication that it is doing this, but it is standard behavior. If you go into Firebug or the console and look at the network traffic you'll see it first hand.
Second, That example looks like the one from the "Master..." book about Joomla. Could well be that any of numerous flaws and configuration settings anywhere along the technology stack could be the roadblock. I just ran into the same issue today. The real lesson to learn here is, "don't do that". Use a development environment that has better tool chain support and a more straightforward path to success.
Sorry about the bad experience.
For posterity:
I tested your code, verbatim copy-pasted, and it works.
Your problems with the debugger are most likely due to networking / php configuration.
A. as answered by @jerseyboy, the the public javascript debugger at sf.net, being built on JS technology, can only send xmlrpc requests to the same domain hosting it. Either that, or you need to add to your own server support for CORS requests. Note that I have updated the js debugger to show info about this issue.
B. there is a public xmlrpc debugger available at https://gggeek.altervista.org/sw/xmlrpc/debugger/ , which is written in PHP, and as such it does not suffer any limitations in connecting to remote servers. It is recommended to use this one over the js one.
C. all 3 debuggers (public php one, local php one, public js one) have a "show more info" selector, that is useful to make them dump as much information as possible to troubleshoot the issue on the http-call layer
D. debugging with a browser: if you try to access your xmlrpc server's url with a browser, you should get as response a '500 error' page with xml contents. If you get a blank page it means that you have a php fatal error. To troubleshoot it, set display_errors=true
in php.ini, and/or check the webserver's error log
E. it is quite weird that the local php debugger does nothing when hitting the "execute" button. All I can think of is that the form does not get submitted because of JS errors. To troubleshoot those, use the browser's developer's tools js console
Back to the original questions:
Q1 - see point E
Q2 - see points B, C, D, E
精彩评论