1 <?php require_once __DIR__ . "/_prepend.php"; ?><html lang="en">
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>
7 <p>You can see the source to this page here: <a href="introspect.php?showSource=1">introspect.php</a></p>
10 function display_error($r)
12 print "An error occurred: ";
13 print "Code: " . $r->faultCode()
14 . " Reason: '" . $r->faultString() . "'<br/>";
17 $client = new PhpXmlRpc\Client(XMLRPCSERVER);
19 // First off, let's retrieve the list of methods available on the remote server
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);
24 if ($resp->faultCode()) {
29 // Then, retrieve the signature and help text of each available method
30 foreach ($v as $methodName) {
31 print "<h4>" . $methodName->scalarval() . "</h4>\n";
32 // build messages first, add params later
33 $m1 = new PhpXmlRpc\Request('system.methodHelp');
34 $m2 = new PhpXmlRpc\Request('system.methodSignature');
35 $val = new PhpXmlRpc\Value($methodName->scalarval(), "string");
38 // Send multiple requests in one http call.
39 // If server does not support multicall, client will automatically fall back to 2 separate calls
40 $ms = array($m1, $m2);
41 $rs = $client->send($ms);
42 if ($rs[0]->faultCode()) {
43 display_error($rs[0]);
45 $val = $rs[0]->value();
46 $txt = $val->scalarval();
48 print "<h4>Documentation</h4><p>${txt}</p>\n";
50 print "<p>No documentation available.</p>\n";
53 if ($rs[1]->faultCode()) {
54 display_error($rs[1]);
56 print "<h4>Signature</h4><p>\n";
57 // note: using PhpXmlRpc\Encoder::decode() here would lead to cleaner code
58 $val = $rs[1]->value();
59 if ($val->kindOf() == "array") {
60 foreach ($val as $x) {
62 print "<code>" . htmlspecialchars($ret->scalarval()) . " "
63 . htmlspecialchars($methodName->scalarval()) . "(";
64 if ($x->count() > 1) {
65 for ($k = 1; $k < $x->count(); $k++) {
67 print htmlspecialchars($y->scalarval());
68 if ($k < $x->count() - 1) {
73 print ")</code><br/>\n";
76 print "Signature unknown\n";
84 </html><?php require_once __DIR__ . "/_append.php"; ?>