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/>";
18 // 'new style' client constructor
19 $client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
20 print "<h3>methods available at http://" . $client->server . $client->path . "</h3>\n";
21 $req = new PhpXmlRpc\Request('system.listMethods');
22 $resp = $client->send($req);
23 if ($resp->faultCode()) {
27 for ($i = 0; $i < $v->arraysize(); $i++) {
28 $mname = $v->arraymem($i);
29 print "<h4>" . $mname->scalarval() . "</h4>\n";
30 // build messages first, add params later
31 $m1 = new PhpXmlRpc\Request('system.methodHelp');
32 $m2 = new PhpXmlRpc\Request('system.methodSignature');
33 $val = new PhpXmlRpc\Value($mname->scalarval(), "string");
36 // send multiple messages in one pass.
37 // If server does not support multicall, client will fall back to 2 separate calls
38 $ms = array($m1, $m2);
39 $rs = $client->send($ms);
40 if ($rs[0]->faultCode()) {
41 display_error($rs[0]);
43 $val = $rs[0]->value();
44 $txt = $val->scalarval();
46 print "<h4>Documentation</h4><p>${txt}</p>\n";
48 print "<p>No documentation available.</p>\n";
51 if ($rs[1]->faultCode()) {
52 display_error($rs[1]);
54 print "<h4>Signature</h4><p>\n";
55 $val = $rs[1]->value();
56 if ($val->kindOf() == "array") {
57 for ($j = 0; $j < $val->arraysize(); $j++) {
58 $x = $val->arraymem($j);
59 $ret = $x->arraymem(0);
60 print "<code>" . $ret->scalarval() . " "
61 . $mname->scalarval() . "(";
62 if ($x->arraysize() > 1) {
63 for ($k = 1; $k < $x->arraysize(); $k++) {
64 $y = $x->arraymem($k);
65 print $y->scalarval();
66 if ($k < $x->arraysize() - 1) {
71 print ")</code><br/>\n";
74 print "Signature unknown\n";