From 1a762a79a3b917ba664a66b0507355e795b69442 Mon Sep 17 00:00:00 2001 From: gggeek Date: Sat, 7 Jan 2023 21:53:38 +0000 Subject: [PATCH] improve demo files pII: small improvements to the client demos --- demo/client/agesort.php | 6 ++++-- demo/client/parallel.php | 16 ++++++++++++---- demo/client/proxy.php | 8 ++++---- demo/client/which.php | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/demo/client/agesort.php b/demo/client/agesort.php index 3e747d9c..e6b863e6 100644 --- a/demo/client/agesort.php +++ b/demo/client/agesort.php @@ -6,7 +6,9 @@ output('

Agesort demo

Send an array of "name" => "age" pairs to the server that will send it back sorted.

-

The source code demonstrates basic lib usage, including handling of xmlrpc arrays and structs

+

The source code demonstrates basic lib usage, including manual creation of xml-rpc arrays and structs

+

Have a look at getstatename.php for automatic encoding and decoding, and at + vardemo.php for more examples of manual encoding and decoding

You can see the source to this page here: agesort.php

'); @@ -58,7 +60,7 @@ if (!$resp->faultCode()) { } else { output("An error occurred:
");
     output("Code: " . htmlspecialchars($resp->faultCode()) .
-        "\nReason: '" . htmlspecialchars($resp->faultString()) . '\'

'); + "\nReason: '" . htmlspecialchars($resp->faultString()) . "'
"); } output("\n"); diff --git a/demo/client/parallel.php b/demo/client/parallel.php index db302a19..25b6bb4e 100644 --- a/demo/client/parallel.php +++ b/demo/client/parallel.php @@ -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"; diff --git a/demo/client/proxy.php b/demo/client/proxy.php index 800ee86f..2108e602 100644 --- a/demo/client/proxy.php +++ b/demo/client/proxy.php @@ -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)); diff --git a/demo/client/which.php b/demo/client/which.php index 21eb83b7..888c751d 100644 --- a/demo/client/which.php +++ b/demo/client/which.php @@ -10,8 +10,8 @@ output('

You can see the source to this page here: which.php

'); -$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(); -- 2.47.0