clean up demo files
authorgggeek <giunta.gaetano@gmail.com>
Fri, 27 May 2022 10:18:50 +0000 (10:18 +0000)
committergggeek <giunta.gaetano@gmail.com>
Fri, 27 May 2022 10:18:50 +0000 (10:18 +0000)
demo/client/agesort.php
demo/client/getstatename.php
demo/client/introspect.php
demo/client/mail.php
demo/client/proxy.php
demo/client/which.php
demo/client/wrap.php
demo/server/discuss.php
demo/server/proxy.php
demo/server/server.php
demo/vardemo.php

index 9ad397f..6b7be6a 100644 (file)
@@ -1,21 +1,21 @@
-<?php require_once __DIR__ . "/_prepend.php"; ?><html lang="en">
+<?php
+require_once __DIR__ . "/_prepend.php";
+
+output('<html lang="en">
 <head><title>xmlrpc - Agesort demo</title></head>
 <body>
 <h1>Agesort demo</h1>
-
-<h2>Send an array of 'name' => 'age' pairs to the server that will send it back sorted.</h2>
-
+<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>
-
 <p>You can see the source to this page here: <a href="agesort.php?showSource=1">agesort.php</a></p>
-<?php
+');
 
 $inAr = array("Dave" => 24, "Edd" => 45, "Joe" => 37, "Fred" => 27);
-print "This is the input data:<br/><pre>";
+output("This is the input data:<br/><pre>");
 foreach ($inAr as $key => $val) {
-    print $key . ", " . $val . "\n";
+    output($key . ", " . $val . "\n");
 }
-print "</pre>";
+output("</pre>");
 
 // Create parameters from the input array: an xmlrpc array of xmlrpc structs
 $p = array();
@@ -29,7 +29,7 @@ foreach ($inAr as $key => $val) {
     );
 }
 $v = new PhpXmlRpc\Value($p, "array");
-print "Encoded into xmlrpc format it looks like this: <pre>\n" . htmlentities($v->serialize()) . "</pre>\n";
+output("Encoded into xmlrpc format it looks like this: <pre>\n" . htmlentities($v->serialize()) . "</pre>\n");
 
 // create client and message objects
 $req = new PhpXmlRpc\Request('examples.sortByAge', array($v));
@@ -39,27 +39,27 @@ $client = new PhpXmlRpc\Client(XMLRPCSERVER);
 $client->setDebug(2);
 
 // send request
-print "Now sending request (detailed debug info follows)";
+output("Now sending request (detailed debug info follows)");
 $resp = $client->send($req);
 
 // check response for errors, and take appropriate action
 if (!$resp->faultCode()) {
-    print "The server gave me these results:<pre>";
+    output("The server gave me these results:<pre>");
     $value = $resp->value();
     foreach ($value as $struct) {
         $name = $struct["name"];
         $age = $struct["age"];
-        print htmlspecialchars($name->scalarval()) . ", " . htmlspecialchars($age->scalarval()) . "\n";
+        output(htmlspecialchars($name->scalarval()) . ", " . htmlspecialchars($age->scalarval()) . "\n");
     }
 
-    print "<hr/>For nerds: I got this value back<br/><pre>" .
-        htmlentities($resp->serialize()) . "</pre><hr/>\n";
+    output("<hr/>For nerds: I got this value back<br/><pre>" .
+        htmlentities($resp->serialize()) . "</pre><hr/>\n");
 } else {
-    print "An error occurred:<pre>";
-    print "Code: " . htmlspecialchars($resp->faultCode()) .
-        "\nReason: '" . htmlspecialchars($resp->faultString()) . '\'</pre><hr/>';
+    output("An error occurred:<pre>");
+    output("Code: " . htmlspecialchars($resp->faultCode()) .
+        "\nReason: '" . htmlspecialchars($resp->faultString()) . '\'</pre><hr/>');
 }
 
-?>
-</body>
-</html><?php require_once __DIR__ . "/_append.php"; ?>
+output("</body></html>\n");
+
+require_once __DIR__ . "/_append.php";
index a83d907..89b56cd 100644 (file)
@@ -1,14 +1,14 @@
-<?php require_once __DIR__ . "/_prepend.php"; ?><html lang="en">
+<?php
+require_once __DIR__ . "/_prepend.php";
+
+output('<html lang="en">
 <head><title>xmlrpc - Getstatename demo</title></head>
 <body>
 <h1>Getstatename demo</h1>
-
 <h2>Send a U.S. state number to the server and get back the state name</h2>
-
 <h3>The code demonstrates usage of automatic encoding/decoding of php variables into xmlrpc values</h3>
-
 <p>You can see the source to this page here: <a href="getstatename.php?showSource=1">getstatename.php</a></p>
-<?php
+');
 
 if (isset($_POST["stateno"]) && $_POST["stateno"] != "") {
     $stateNo = (integer)$_POST["stateno"];
@@ -16,27 +16,29 @@ if (isset($_POST["stateno"]) && $_POST["stateno"] != "") {
     $req = new PhpXmlRpc\Request('examples.getStateName',
         array($encoder->encode($stateNo))
     );
-    print "Sending the following request:<pre>\n\n" . htmlentities($req->serialize()) . "\n\n</pre>Debug info of server data follows...\n\n";
+    output("Sending the following request:<pre>\n\n" . htmlentities($req->serialize()) . "\n\n</pre>Debug info of server data follows...\n\n");
     $client = new PhpXmlRpc\Client(XMLRPCSERVER);
     $client->setDebug(1);
     $r = $client->send($req);
     if (!$r->faultCode()) {
         $v = $r->value();
-        print "<br/>State number <b>" . $stateNo . "</b> is <b>"
-            . htmlspecialchars($encoder->decode($v)) . "</b><br/><br/>";
+        output("<br/>State number <b>" . $stateNo . "</b> is <b>"
+            . htmlspecialchars($encoder->decode($v)) . "</b><br/><br/>");
     } else {
-        print "An error occurred: ";
-        print "Code: " . htmlspecialchars($r->faultCode())
-            . " Reason: '" . htmlspecialchars($r->faultString()) . "'</pre><br/>";
+        output("An error occurred: ");
+        output("Code: " . htmlspecialchars($r->faultCode())
+            . " Reason: '" . htmlspecialchars($r->faultString()) . "'</pre><br/>");
     }
 } else {
     $stateNo = "";
 }
 
-print "<form action=\"getstatename.php\" method=\"POST\">
-<input name=\"stateno\" value=\"" . $stateNo . "\"><input type=\"submit\" value=\"go\" name=\"submit\"></form>
-<p>Enter a state number to query its name</p>";
+output("<form action=\"getstatename.php\" method=\"POST\">
+<input name=\"stateno\" value=\"" . $stateNo . "\">
+<input type=\"submit\" value=\"go\" name=\"submit\">
+</form>
+<p>Enter a state number to query its name</p>");
+
+output("</body></html>\n");
 
-?>
-</body>
-</html><?php require_once __DIR__ . "/_append.php"; ?>
+require_once __DIR__ . "/_append.php";
index f8bb6b0..1c74ee6 100644 (file)
@@ -1,23 +1,26 @@
-<?php require_once __DIR__ . "/_prepend.php"; ?><html lang="en">
+<?php
+
+require_once __DIR__ . "/_prepend.php";
+
+output('<html lang="en">
 <head><title>xmlrpc - Introspect demo</title></head>
 <body>
 <h1>Introspect demo</h1>
 <h2>Query server for available methods and their description</h2>
 <h3>The code demonstrates usage of multicall and introspection methods</h3>
 <p>You can see the source to this page here: <a href="introspect.php?showSource=1">introspect.php</a></p>
-<?php
+');
 
 function display_error($r)
 {
-    print "An error occurred: ";
-    print "Code: " . $r->faultCode()
-        . " Reason: '" . $r->faultString() . "'<br/>";
+    output("An error occurred: ");
+    output("Code: " . $r->faultCode() . " Reason: '" . $r->faultString() . "'<br/>");
 }
 
 $client = new PhpXmlRpc\Client(XMLRPCSERVER);
 
 // First off, let's retrieve the list of methods available on the remote server
-print "<h3>methods available at http://" . $client->server . $client->path . "</h3>\n";
+output("<h3>methods available at http://" . $client->server . $client->path . "</h3>\n");
 $req = new PhpXmlRpc\Request('system.listMethods');
 $resp = $client->send($req);
 
@@ -28,7 +31,7 @@ if ($resp->faultCode()) {
 
     // Then, retrieve the signature and help text of each available method
     foreach ($v as $methodName) {
-        print "<h4>" . $methodName->scalarval() . "</h4>\n";
+        output("<h4>" . $methodName->scalarval() . "</h4>\n");
         // build messages first, add params later
         $m1 = new PhpXmlRpc\Request('system.methodHelp');
         $m2 = new PhpXmlRpc\Request('system.methodSignature');
@@ -45,40 +48,41 @@ if ($resp->faultCode()) {
             $val = $rs[0]->value();
             $txt = $val->scalarval();
             if ($txt != "") {
-                print "<h4>Documentation</h4><p>${txt}</p>\n";
+                output("<h4>Documentation</h4><p>${txt}</p>\n");
             } else {
-                print "<p>No documentation available.</p>\n";
+                output("<p>No documentation available.</p>\n");
             }
         }
         if ($rs[1]->faultCode()) {
             display_error($rs[1]);
         } else {
-            print "<h4>Signature</h4><p>\n";
+            output("<h4>Signature</h4><p>\n");
             // note: using PhpXmlRpc\Encoder::decode() here would lead to cleaner code
             $val = $rs[1]->value();
             if ($val->kindOf() == "array") {
                 foreach ($val as $x) {
                     $ret = $x[0];
-                    print "<code>" . htmlspecialchars($ret->scalarval()) . " "
-                        . htmlspecialchars($methodName->scalarval()) . "(";
+                    output("<code>" . htmlspecialchars($ret->scalarval()) . " "
+                        . htmlspecialchars($methodName->scalarval()) . "(");
                     if ($x->count() > 1) {
                         for ($k = 1; $k < $x->count(); $k++) {
                             $y = $x[$k];
-                            print htmlspecialchars($y->scalarval());
+                            output(htmlspecialchars($y->scalarval()));
                             if ($k < $x->count() - 1) {
-                                print ", ";
+                                output(", ");
                             }
                         }
                     }
-                    print ")</code><br/>\n";
+                    output(")</code><br/>\n");
                 }
             } else {
-                print "Signature unknown\n";
+                output("Signature unknown\n");
             }
-            print "</p>\n";
+            output("</p>\n");
         }
     }
 }
-?>
-</body>
-</html><?php require_once __DIR__ . "/_append.php"; ?>
+
+output("</body></html>\n");
+
+require_once __DIR__ . "/_append.php";
index 4907a7a..cd726b5 100644 (file)
@@ -1,17 +1,18 @@
-<?php require_once __DIR__ . "/_prepend.php"; ?><html lang="en">
+<?php
+require_once __DIR__ . "/_prepend.php";
+
+output('<html lang="en">
 <head><title>xmlrpc - Mail demo</title></head>
 <body>
 <h1>Mail demo</h1>
-
 <p>This form enables you to send mail via an XML-RPC server.
     When you press <kbd>Send</kbd> this page will reload, showing you the XML-RPC request sent to the host server, the
     XML-RPC response received and the internal evaluation done by the PHP implementation.</p>
-
 <p>You can see the source to this page here: <a href="mail.php?showSource=1">mail.php</a><br/>
     And the source to a functionally identical mail-by-XML-RPC server in the file <a
-        href="../server/server.php?showSource=1">server.php</a> included with the library (look for the 'mail_send'
+        href="../server/server.php?showSource=1">server.php</a> included with the library (look for the "mail_send"
     method)</p>
-<?php
+');
 
 if (isset($_POST["mailto"]) && $_POST["mailto"]) {
     $server = XMLRPCSERVER;
@@ -29,17 +30,17 @@ if (isset($_POST["mailto"]) && $_POST["mailto"]) {
     $client->setDebug(2);
     $resp = $client->send($req);
     if (!$resp->faultCode()) {
-        print "Mail sent OK<br/>\n";
+        output("Mail sent OK<br/>\n");
     } else {
-        print "<font color=\"red\">";
-        print "Mail send failed<br/>\n";
-        print "Fault: ";
-        print "Code: " . htmlspecialchars($resp->faultCode()) .
-            " Reason: '" . htmlspecialchars($resp->faultString()) . "'<br/>";
-        print "</font><br/>";
+        output("<font color=\"red\">");
+        output("Mail send failed<br/>\n");
+        output("Fault: ");
+        output("Code: " . htmlspecialchars($resp->faultCode()) .
+            " Reason: '" . htmlspecialchars($resp->faultString()) . "'<br/>");
+        output("</font><br/>");
     }
 }
-?>
+output('
 <form method="POST">
     From <input size="60" name="mailfrom" value=""/><br/>
     <hr/>
@@ -53,4 +54,7 @@ if (isset($_POST["mailto"]) && $_POST["mailto"]) {
     <input type="Submit" value="Send"/>
 </form>
 </body>
-</html><?php require_once __DIR__ . "/_append.php"; ?>
+</html>
+');
+
+require_once __DIR__ . "/_append.php";
index 9b7fce6..8e89e81 100644 (file)
@@ -1,20 +1,24 @@
-<?php require_once __DIR__ . "/_prepend.php"; ?><html lang="en">
+<?php
+require_once __DIR__ . "/_prepend.php";
+
+output('<html lang="en">
 <head><title>xmlrpc - Proxy demo</title></head>
 <body>
 <h1>proxy demo</h1>
-<h2>Query server using a 'proxy' object</h2>
-<h3>The code demonstrates usage for the terminally lazy. For a more complete proxy, look at at the Wrapper class</h3>
+<h2>Query server using a "proxy" object</h2>
+<h3>The code demonstrates usage for the terminally lazy. For a more complete proxy, look at the Wrapper class</h3>
 <p>You can see the source to this page here: <a href="proxy.php?showSource=1">proxy.php</a></p>
-<?php
+');
 
 class PhpXmlRpcProxy
 {
     protected $client;
-    protected $prefix = 'examples.';
+    protected $prefix;
 
-    public function __construct(PhpXmlRpc\Client $client)
+    public function __construct(PhpXmlRpc\Client $client, $prefix = 'examples.')
     {
         $this->client = $client;
+        $this->prefix = $prefix;
     }
 
     /**
@@ -48,12 +52,29 @@ class PhpXmlRpcProxy
             return $resp->value();
         }
     }
+
+    /**
+     * In case the remote method name has characters which are not valid as php method names, use this.
+     *
+     * @param string $name remote function name. Will be prefixed
+     * @param array $arguments
+     *
+     * @return mixed
+     *
+     * @throws Exception
+     */
+    public function call($name, $arguments)
+    {
+        return $this->__call($name, $arguments);
+    }
 }
 
 $stateNo = rand(1, 51);
 $proxy = new PhpXmlRpcProxy(new PhpXmlRpc\Client(XMLRPCSERVER));
 $stateName = $proxy->getStateName($stateNo);
 
-echo "State $stateNo is ".htmlspecialchars($stateName);
+output("State $stateNo is ".htmlspecialchars($stateName));
+
+output("</body></html>\n");
 
 require_once __DIR__ . "/_append.php";
index 1c1ba36..23a08b3 100644 (file)
@@ -1,11 +1,14 @@
-<?php require_once __DIR__ . "/_prepend.php"; ?><html lang="en">
+<?php
+require_once __DIR__ . "/_prepend.php";
+
+output('<html lang="en">
 <head><title>xmlrpc - Which toolkit demo</title></head>
 <body>
 <h1>Which toolkit demo</h1>
 <h2>Query server for toolkit information</h2>
 <h3>The code demonstrates usage of the PhpXmlRpc\Encoder class</h3>
 <p>You can see the source to this page here: <a href="which.php?showSource=1">which.php</a></p>
-<?php
+');
 
 $req = new PhpXmlRpc\Request('interopEchoTests.whichToolkit', array());
 $client = new PhpXmlRpc\Client(XMLRPCSERVER);
@@ -13,17 +16,18 @@ $resp = $client->send($req);
 if (!$resp->faultCode()) {
     $encoder = new PhpXmlRpc\Encoder();
     $value = $encoder->decode($resp->value());
-    print "Toolkit info:<br/>\n";
-    print "<pre>";
-    print "name: " . htmlspecialchars($value["toolkitName"]) . "\n";
-    print "version: " . htmlspecialchars($value["toolkitVersion"]) . "\n";
-    print "docs: " . htmlspecialchars($value["toolkitDocsUrl"]) . "\n";
-    print "os: " . htmlspecialchars($value["toolkitOperatingSystem"]) . "\n";
-    print "</pre>";
+    output("Toolkit info:<br/>\n");
+    output("<pre>");
+    output("name: " . htmlspecialchars($value["toolkitName"]) . "\n");
+    output("version: " . htmlspecialchars($value["toolkitVersion"]) . "\n");
+    output("docs: " . htmlspecialchars($value["toolkitDocsUrl"]) . "\n");
+    output("os: " . htmlspecialchars($value["toolkitOperatingSystem"]) . "\n");
+    output("</pre>");
 } else {
-    print "An error occurred: ";
-    print "Code: " . htmlspecialchars($resp->faultCode()) . " Reason: '" . htmlspecialchars($resp->faultString()) . "'\n";
+    output("An error occurred: ");
+    output("Code: " . htmlspecialchars($resp->faultCode()) . " Reason: '" . htmlspecialchars($resp->faultString()) . "'\n");
 }
-?>
-</body>
-</html><?php require_once __DIR__ . "/_append.php"; ?>
+
+output("</body></html>\n");
+
+require_once __DIR__ . "/_append.php";
index 4e3db40..d752349 100644 (file)
@@ -1,25 +1,28 @@
-<?php require_once __DIR__ . "/_prepend.php"; ?><html lang="en">
+<?php
+require_once __DIR__ . "/_prepend.php";
+
+output('<html lang="en">
 <head><title>xmlrpc - Webservice wrappper demo</title></head>
 <body>
 <h1>Webservice wrappper demo</h1>
 
 <h2>Wrap methods exposed by server into php functions</h2>
 
-<h3>The code demonstrates usage of some the most automagic client usage possible:<br/>
+<h3>The code demonstrates usage of some of the most automagic client usage possible:<br/>
     1) client that returns php values instead of xmlrpc value objects<br/>
     2) wrapping of remote methods into php functions<br/>
     See also proxy.php for an alternative take
 </h3>
 <p>You can see the source to this page here: <a href="wrap.php?showSource=1">wrap.php</a></p>
-<?php
+');
 
 $client = new PhpXmlRpc\Client(XMLRPCSERVER);
 $client->return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals
 $resp = $client->send(new PhpXmlRpc\Request('system.listMethods'));
 if ($resp->faultCode()) {
-    echo "<p>Server methods list could not be retrieved: error {$resp->faultCode()} '" . htmlspecialchars($resp->faultString()) . "'</p>\n";
+    output("<p>Server methods list could not be retrieved: error {$resp->faultCode()} '" . htmlspecialchars($resp->faultString()) . "'</p>\n");
 } else {
-    echo "<p>Server methods list retrieved, now wrapping it up...</p>\n<ul>\n";
+    output("<p>Server methods list retrieved, now wrapping it up...</p>\n<ul>\n");
     flush();
 
     $callable = false;
@@ -29,24 +32,25 @@ if ($resp->faultCode()) {
         if ($methodName == 'examples.getStateName') {
             $callable = $wrapper->wrapXmlrpcMethod($client, $methodName);
             if ($callable) {
-                echo "<li>Remote server method " . htmlspecialchars($methodName) . " wrapped into php function</li>\n";
+                output("<li>Remote server method " . htmlspecialchars($methodName) . " wrapped into php function</li>\n");
             } else {
-                echo "<li>Remote server method " . htmlspecialchars($methodName) . " could not be wrapped!</li>\n";
+                output("<li>Remote server method " . htmlspecialchars($methodName) . " could not be wrapped!</li>\n");
             }
             break;
         }
     }
-    echo "</ul>\n";
+    output("</ul>\n");
     flush();
 
     if ($callable) {
-        echo "Now testing function for remote method to convert U.S. state number into state name";
+        output("Now testing function for remote method to convert U.S. state number into state name");
         $stateNum = rand(1, 51);
         // the 2nd parameter gets added to the closure - it is the debug level to be used for the client
         $stateName = $callable($stateNum, 2);
-        echo "State $stateNum is ".htmlspecialchars($stateName);
+        output("State $stateNum is ".htmlspecialchars($stateName));
     }
 }
-?>
-</body>
-</html><?php require_once __DIR__ . "/_append.php"; ?>
+
+output("</body></html>\n");
+
+require_once __DIR__ . "/_append.php";
index ca5dd7d..08058cd 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+/**
+ * A basic comment server. Given an ID it will store a list of names and comment texts against it.
+ * It uses a Berkeley DB database for storage.
+ */
 
 require_once __DIR__ . "/_prepend.php";
 
@@ -75,6 +79,8 @@ function getComments($req)
                 );
             }
         }
+    } else {
+        $err = "Unable to open comments database.";
     }
     // if we generated an error, create an error return response
     if ($err) {
index a0a0f1d..f72a835 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /**
  * XMLRPC server acting as proxy for requests to other servers
- * (useful e.g. for ajax-originated calls that can only connect back to
- * the originating server).
- * For an example of a transparent reverse-proxy, see the ReverseProxy class in package phpxmlrpc/extras
+ * (useful e.g. for ajax-originated calls that can only connect back to the originating server).
+ * NB: this is an OPEN RELAY. It is meant as a demo, not to be used in production!
+ * For an example of a transparent reverse-proxy, see the ReverseProxy class in package phpxmlrpc/extras.
  *
  * @author Gaetano Giunta
  * @copyright (C) 2006-2021 G. Giunta
@@ -28,6 +28,7 @@ function forward_request($req)
     // create client
     $timeout = 0;
     $url = $encoder->decode($req->getParam(0));
+    // NB: here we should validate the received url, using f.e. a whitelist...
     $client = new PhpXmlRpc\Client($url);
 
     if ($req->getNumParams() > 3) {
@@ -73,7 +74,7 @@ function forward_request($req)
     return $client->send($req, $timeout);
 }
 
-// run the server
+// Run the server
 // NB: take care not to output anything else after this call, as it will mess up the responses and it will be hard to
 // debug. In case you have to do so, at least re-emit a correct Content-Length http header (requires output buffering)
 $server = new PhpXmlRpc\Server(
index 4ab3be5..a40a69d 100644 (file)
@@ -4,9 +4,10 @@
  *
  * Implements a lot of webservices, including a suite of services used for interoperability testing (validator1 methods),
  * and some whose only purpose is to be used for unit-testing the library.
+ * It also allows the caller to configure specific features by using "out of band" query string parameters.
  *
  * Please _do not_ copy this file verbatim into your production server.
- **/
+ */
 
 require_once __DIR__ . "/_prepend.php";
 
index 70436ff..0390f85 100644 (file)
@@ -1,16 +1,19 @@
-<?php require_once __DIR__ . "/client/_prepend.php"; ?><html lang="en">
+<?php
+require_once __DIR__ . "/client/_prepend.php";
+
+output('html lang="en">
 <head><title>xmlrpc</title></head>
 <body>
-<?php
+');
 
 $req = new PhpXmlRpc\Request('examples.getStateName');
 
-print "<h3>Testing value serialization</h3>\n";
+output("<h3>Testing value serialization</h3>\n");
 
 $v = new PhpXmlRpc\Value(23, "int");
-print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
+output("<PRE>" . htmlentities($v->serialize()) . "</PRE>");
 $v = new PhpXmlRpc\Value("What are you saying? >> << &&");
-print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
+output("<PRE>" . htmlentities($v->serialize()) . "</PRE>");
 
 $v = new PhpXmlRpc\Value(
     array(
@@ -21,7 +24,7 @@ $v = new PhpXmlRpc\Value(
     "array"
 );
 
-print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
+output("<PRE>" . htmlentities($v->serialize()) . "</PRE>");
 
 $v = new PhpXmlRpc\Value(
     array(
@@ -49,11 +52,11 @@ $v = new PhpXmlRpc\Value(
     "struct"
 );
 
-print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
+output("<PRE>" . htmlentities($v->serialize()) . "</PRE>");
 
 $w = new PhpXmlRpc\Value(array($v, new PhpXmlRpc\Value("That was the struct!")), "array");
 
-print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
+output("<PRE>" . htmlentities($w->serialize()) . "</PRE>");
 
 $w = new PhpXmlRpc\Value("Mary had a little lamb,
 Whose fleece was white as snow,
@@ -65,29 +68,29 @@ She tied it to a pylon
 Ten thousand volts went down its back
 And turned it into nylon", "base64"
 );
-print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
-print "<PRE>Value of base64 string is: '" . $w->scalarval() . "'</PRE>";
+output("<PRE>" . htmlentities($w->serialize()) . "</PRE>");
+output("<PRE>Value of base64 string is: '" . $w->scalarval() . "'</PRE>");
 
 $req->method('');
 $req->addParam(new PhpXmlRpc\Value("41", "int"));
 
-print "<h3>Testing request serialization</h3>\n";
+output("<h3>Testing request serialization</h3>\n");
 $op = $req->serialize();
-print "<PRE>" . htmlentities($op) . "</PRE>";
+output("<PRE>" . htmlentities($op) . "</PRE>");
 
-print "<h3>Testing ISO date format</h3><pre>\n";
+output("<h3>Testing ISO date format</h3><pre>\n");
 
 $t = time();
 $date = PhpXmlRpc\Helper\Date::iso8601Encode($t);
-print "Now is $t --> $date\n";
-print "Or in UTC, that is " . PhpXmlRpc\Helper\Date::iso8601Encode($t, 1) . "\n";
+output("Now is $t --> $date\n");
+output("Or in UTC, that is " . PhpXmlRpc\Helper\Date::iso8601Encode($t, 1) . "\n");
 $tb = PhpXmlRpc\Helper\Date::iso8601Decode($date);
-print "That is to say $date --> $tb\n";
-print "Which comes out at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb) . "\n";
-print "Which was the time in UTC at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb, 1) . "\n";
+output("That is to say $date --> $tb\n");
+output("Which comes out at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb) . "\n");
+output("Which was the time in UTC at " . PhpXmlRpc\Helper\Date::iso8601Encode($tb, 1) . "\n");
+
+output("</pre>\n");
 
-print "</pre>\n";
+output('</body></html>');
 
-?>
-</body>
-</html><?php require_once __DIR__ . "/client/_append.php"; ?>
+require_once __DIR__ . "/client/_append.php";