improve demo files pII: small improvements to the client demos
authorgggeek <giunta.gaetano@gmail.com>
Sat, 7 Jan 2023 21:53:38 +0000 (21:53 +0000)
committergggeek <giunta.gaetano@gmail.com>
Sat, 7 Jan 2023 21:53:38 +0000 (21:53 +0000)
demo/client/agesort.php
demo/client/parallel.php
demo/client/proxy.php
demo/client/which.php

index 3e747d9..e6b863e 100644 (file)
@@ -6,7 +6,9 @@ output('<html lang="en">
 <body>
 <h1>Agesort demo</h1>
 <h2>Send an array of "name" => "age" pairs to the server that will send it back sorted.</h2>
-<h3>The source code demonstrates basic lib usage, including handling of xmlrpc arrays and structs</h3>
+<h3>The source code demonstrates basic lib usage, including manual creation of xml-rpc arrays and structs</h3>
+<p>Have a look at <a href="getstatename.php">getstatename.php</a> for automatic encoding and decoding, and at
+    <a href="../vardemo.php">vardemo.php</a> for more examples of manual encoding and decoding</p>
 <p>You can see the source to this page here: <a href="agesort.php?showSource=1">agesort.php</a></p>
 ');
 
@@ -58,7 +60,7 @@ if (!$resp->faultCode()) {
 } else {
     output("An error occurred:<pre>");
     output("Code: " . htmlspecialchars($resp->faultCode()) .
-        "\nReason: '" . htmlspecialchars($resp->faultString()) . '\'</pre><hr/>');
+        "\nReason: '" . htmlspecialchars($resp->faultString()) . "'</pre><hr/>");
 }
 
 output("</body></html>\n");
index db302a1..25b6bb4 100644 (file)
@@ -9,7 +9,7 @@ use PhpXmlRpc\Response;
 
 /**
  * A class taking advantage of cURL to send many requests in parallel (to a single server), for when the given server
- * does not support system.multicall method
+ * does not support the system.multicall method
  */
 class ParallelClient extends Client
 {
@@ -106,18 +106,26 @@ for ($i = 0; $i < $num_tests; $i++) {
 $client = new ParallelClient(XMLRPCSERVER);
 $client->no_multicall = true;
 
+// a minimal benchmark - use 3 strategies to execute the same 25 calls: sequentially, using parallel http requests, and
+// using a single system.multiCall request
+
+echo "Making $num_tests xml-rpc calls...\n";
+flush();
+
 $t = microtime(true);
 $resp = $client->send($reqs);
 $t = microtime(true) - $t;
-echo "Sequential send: $t secs\n";
+echo "Sequential send: " . sprintf('%.3f', $t) . " secs.\n";
+flush();
 
 $t = microtime(true);
 $resp = $client->sendParallel($reqs);
 $t = microtime(true) - $t;
-echo "Parallel send: $t secs\n";
+echo "Parallel send: " . sprintf('%.3f', $t) . " secs.\n";
+flush();
 
 $client->no_multicall = false;
 $t = microtime(true);
 $resp = $client->send($reqs);
 $t = microtime(true) - $t;
-echo "Multicall send: $t secs\n";
+echo "Multicall send: " . sprintf('%.3f', $t) . " secs.\n";
index 800ee86..2108e60 100644 (file)
@@ -24,13 +24,12 @@ class PhpXmlRpcProxy
     }
 
     /**
-     * Translates any method call to an xmlrpc call.
+     * Translates any method call to an xml-rpc call.
      *
      * @author Toth Istvan
      *
      * @param string $name remote function name. Will be prefixed
      * @param array $arguments
-     *
      * @return mixed
      *
      * @throws Exception
@@ -60,7 +59,6 @@ class PhpXmlRpcProxy
      *
      * @param string $name remote function name. Will be prefixed
      * @param array $arguments
-     *
      * @return mixed
      *
      * @throws Exception
@@ -71,8 +69,10 @@ class PhpXmlRpcProxy
     }
 }
 
-$stateNo = rand(1, 51);
 $proxy = new PhpXmlRpcProxy(new PhpXmlRpc\Client(XMLRPCSERVER));
+
+$stateNo = rand(1, 51);
+// sadly, no IDE will be able to assist with autocompletion for this method, unless you manually add an equivalent phpdoc comment...
 $stateName = $proxy->getStateName($stateNo);
 
 output("State $stateNo is ".htmlspecialchars($stateName));
index 21eb83b..888c751 100644 (file)
@@ -10,8 +10,8 @@ output('<html lang="en">
 <p>You can see the source to this page here: <a href="which.php?showSource=1">which.php</a></p>
 ');
 
-$req = new PhpXmlRpc\Request('interopEchoTests.whichToolkit', array());
 $client = new PhpXmlRpc\Client(XMLRPCSERVER);
+$req = new PhpXmlRpc\Request('interopEchoTests.whichToolkit', array());
 $resp = $client->send($req);
 if (!$resp->faultCode()) {
     $encoder = new PhpXmlRpc\Encoder();