2 <head><title>xmlrpc - Introspect demo</title></head>
4 <h1>Introspect demo</h1>
5 <h2>Query server for available methods and their description</h2>
6 <h3>The code demonstrates usage of multicall and introspection methods</h3>
9 include_once __DIR__ . "/../../src/Autoloader.php";
10 PhpXmlRpc\Autoloader::register();
12 function display_error($r)
14 print "An error occurred: ";
15 print "Code: " . $r->faultCode()
16 . " Reason: '" . $r->faultString() . "'<br/>";
19 $client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
21 // First off, let's retrieve the list of methods available on the remote server
22 print "<h3>methods available at http://" . $client->server . $client->path . "</h3>\n";
23 $req = new PhpXmlRpc\Request('system.listMethods');
24 $resp = $client->send($req);
26 if ($resp->faultCode()) {
31 // Then, retrieve the signature and help text of each available method
32 for ($i = 0; $i < $v->arraysize(); $i++) {
33 $methodName = $v->arraymem($i);
34 print "<h4>" . $methodName->scalarval() . "</h4>\n";
35 // build messages first, add params later
36 $m1 = new PhpXmlRpc\Request('system.methodHelp');
37 $m2 = new PhpXmlRpc\Request('system.methodSignature');
38 $val = new PhpXmlRpc\Value($methodName->scalarval(), "string");
41 // Send multiple requests in one http call.
42 // If server does not support multicall, client will automatically fall back to 2 separate calls
43 $ms = array($m1, $m2);
44 $rs = $client->send($ms);
45 if ($rs[0]->faultCode()) {
46 display_error($rs[0]);
48 $val = $rs[0]->value();
49 $txt = $val->scalarval();
51 print "<h4>Documentation</h4><p>${txt}</p>\n";
53 print "<p>No documentation available.</p>\n";
56 if ($rs[1]->faultCode()) {
57 display_error($rs[1]);
59 print "<h4>Signature</h4><p>\n";
60 // note: using PhpXmlRpc\Encoder::decode() here would lead to cleaner code
61 $val = $rs[1]->value();
62 if ($val->kindOf() == "array") {
63 for ($j = 0; $j < $val->arraysize(); $j++) {
64 $x = $val->arraymem($j);
65 $ret = $x->arraymem(0);
66 print "<code>" . $ret->scalarval() . " "
67 . $methodName->scalarval() . "(";
68 if ($x->arraysize() > 1) {
69 for ($k = 1; $k < $x->arraysize(); $k++) {
70 $y = $x->arraymem($k);
71 print $y->scalarval();
72 if ($k < $x->arraysize() - 1) {
77 print ")</code><br/>\n";
80 print "Signature unknown\n";