2 <head><title>xmlrpc - Proxy demo</title></head>
5 <h2>Query server using a 'proxy' object</h2>
6 <h3>The code demonstrates usage for the terminally lazy</h3>
9 include_once __DIR__ . "/../../src/Autoloader.php";
10 PhpXmlRpc\Autoloader::register();
15 protected $prefix = 'examples.';
17 public function __construct(PhpXmlRpc\Client $client)
19 $this->client = $client;
25 * @param string $name remote function name. Will be prefixed
26 * @param array $arguments
32 function __call($name, $arguments)
34 $encoder = new PhpXmlRpc\Encoder();
35 $valueArray = array();
36 foreach ($arguments as $parameter) {
37 $valueArray[] = $encoder->encode($parameter);
40 // just in case this was set to something else
41 $this->client->return_type = 'phpvals';
43 $resp = $this->client->send(new PhpXmlRpc\Request($this->prefix.$name, $valueArray));
45 if ($resp->faultCode()) {
46 throw new Exception($resp->faultMessage(), $resp->faultCode);
48 return $resp->value();
54 $stateNo = rand(1, 51);
55 $proxy = new PhpXmlRpcProxy(new \PhpXmlRpc\Client('http://phpxmlrpc.sourceforge.net/server.php'));
56 $stateName = $proxy->getStateName($stateNo);
58 echo "State $stateNo is ".htmlspecialchars($stateName);