update docs and NEWS for new release
[plcapi.git] / doc / xmlrpc_php.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <?xml-stylesheet href="docbook-css/driver.css" type="text/css"?>
3 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
4 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
5 <!--
6 PHP-XMLRPC User manual
7 $Id: xmlrpc_php.xml,v 1.27 2008/09/19 18:35:33 ggiunta Exp $
8 -->
9 <book lang="en">
10   <title>XML-RPC for PHP</title>
11
12   <subtitle>version 3.0.0 beta</subtitle>
13
14   <bookinfo>
15     <date>Sep 5, 2009</date>
16
17     <authorgroup>
18       <author>
19         <firstname>Edd</firstname>
20
21         <surname>Dumbill</surname>
22       </author>
23
24       <author>
25         <firstname>Gaetano</firstname>
26
27         <surname>Giunta</surname>
28       </author>
29
30       <author>
31         <firstname>Miles</firstname>
32
33         <surname>Lott</surname>
34       </author>
35
36       <author>
37         <firstname>Justin R.</firstname>
38
39         <surname>Miller</surname>
40       </author>
41
42       <author>
43         <firstname>Andres</firstname>
44
45         <surname>Salomon</surname>
46       </author>
47     </authorgroup>
48
49     <copyright>
50       <year>1999,2000,2001</year>
51
52       <holder>Edd Dumbill, Useful Information Company</holder>
53     </copyright>
54
55     <legalnotice>
56       <para>All rights reserved.</para>
57
58       <para>Redistribution and use in source and binary forms, with or without
59       modification, are permitted provided that the following conditions are
60       met:</para>
61
62       <para><itemizedlist>
63           <listitem>
64             <para>Redistributions of source code must retain the above
65             copyright notice, this list of conditions and the following
66             disclaimer.</para>
67           </listitem>
68
69           <listitem>
70             <para>Redistributions in binary form must reproduce the above
71             copyright notice, this list of conditions and the following
72             disclaimer in the documentation and/or other materials provided
73             with the distribution.</para>
74           </listitem>
75
76           <listitem>
77             <para>Neither the name of the "XML-RPC for PHP" nor the names of
78             its contributors may be used to endorse or promote products
79             derived from this software without specific prior written
80             permission.</para>
81           </listitem>
82         </itemizedlist></para>
83
84       <para>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
85       CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
86       BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
87       FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
88       REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
89       SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
90       TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
91       PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
92       LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
93       NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
94       SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</para>
95     </legalnotice>
96   </bookinfo>
97
98   <chapter id="introduction">
99     <title>Introduction</title>
100
101     <para>XML-RPC is a format devised by <ulink
102     url="http://www.userland.com/">Userland Software</ulink> for achieving
103     remote procedure call via XML using HTTP as the transport. XML-RPC has its
104     own web site, <ulink
105     url="http://www.xmlrpc.com/">www.xmlrpc.com</ulink></para>
106
107     <para>This collection of PHP classes provides a framework for writing
108     XML-RPC clients and servers in PHP.</para>
109
110     <para>Main goals of the project are ease of use, flexibility and
111     completeness.</para>
112
113     <para>The original author is Edd Dumbill of <ulink
114     url="http://usefulinc.com/">Useful Information Company</ulink>. As of the
115     1.0 stable release, the project was opened to wider involvement and moved
116     to <ulink
117     url="http://phpxmlrpc.sourceforge.net/">SourceForge</ulink>.</para>
118
119     <para>A list of XML-RPC implementations for other languages such as Perl
120     and Python can be found on the <ulink
121     url="http://www.xmlrpc.com/">www.xmlrpc.com</ulink> site.</para>
122
123     <sect1>
124       <title>Acknowledgements</title>
125
126       <para>Daniel E. Baumann</para>
127
128       <para>James Bercegay</para>
129
130       <para>Leon Blackwell</para>
131
132       <para>Stephane Bortzmeyer</para>
133
134       <para>Daniel Convissor</para>
135
136       <para>Geoffrey T. Dairiki</para>
137
138       <para>Stefan Esser</para>
139
140       <para>James Flemer</para>
141
142       <para>Ernst de Haan</para>
143
144       <para>Tom Knight</para>
145
146       <para>Axel Kollmorgen</para>
147
148       <para>Peter Kocks</para>
149
150       <para>Daniel Krippner</para>
151
152       <para>S. Kuip</para>
153
154       <para>A. Lambert</para>
155
156       <para>Frederic Lecointre</para>
157
158       <para>Dan Libby</para>
159
160       <para>Arnaud Limbourg</para>
161
162       <para>Ernest MacDougal Campbell III</para>
163
164       <para>Lukasz Mach</para>
165
166       <para>Kjartan Mannes</para>
167
168       <para>Ben Margolin</para>
169
170       <para>Nicolay Mausz</para>
171
172       <para>Justin Miller</para>
173
174       <para>Jan Pfeifer</para>
175
176       <para>Giancarlo Pinerolo</para>
177
178       <para>Peter Russel</para>
179
180       <para>Jean-Jacques Sarton</para>
181
182       <para>Viliam Simko</para>
183
184       <para>Idan Sofer</para>
185
186       <para>Douglas Squirrel</para>
187
188       <para>Heiko Stübner</para>
189
190       <para>Anatoly Techtonik</para>
191
192       <para>Tommaso Trani</para>
193
194       <para>Eric van der Vlist</para>
195
196       <para>Christian Wenz</para>
197
198       <para>Jim Winstead</para>
199
200       <para>Przemyslaw Wroblewski</para>
201
202       <para>Bruno Zanetti Melotti</para>
203     </sect1>
204   </chapter>
205
206   <chapter id="news">
207     <title>What's new</title>
208
209     <para><emphasis>Note:</emphasis> not all items the following list have
210     (yet) been fully documented, and some might not be present in any other
211     chapter in the manual. To find a more detailed description of new
212     functions and methods please take a look at the source code of the
213     library, which is quite thoroughly commented in javadoc-like form.</para>
214
215     <sect1>
216       <title>3.0.0 beta</title>
217
218       <para>This is the first release of the library to only support PHP 5.
219       Some legacy code has been removed, and support for features such as
220       exceptions and dateTime objects introduced.</para>
221
222       <para>The "beta" tag is meant to indicate the fact that the refactoring
223       has been more widespread than in precedent releases and that more
224       changes are likely to be introduced with time - the library is still
225       considered to be production quality.</para>
226
227       <para><itemizedlist>
228           <listitem>
229             <para>improved: removed all usage of php functions deprecated in
230             php 5.3, usage of assign-by-ref when creating new objects
231             etc...</para>
232           </listitem>
233
234           <listitem>
235             <para>improved: add support for the &lt;ex:nil/&gt; tag used by
236             the apache library, both in input and output</para>
237           </listitem>
238
239           <listitem>
240             <para>improved: add support for <classname>dateTime</classname>
241             objects in both in <function>php_xmlrpc_encode</function> and as
242             parameter for constructor of
243             <classname>xmlrpcval</classname></para>
244           </listitem>
245
246           <listitem>
247             <para>improved: add support for timestamps as parameter for
248             constructor of <classname>xmlrpcval</classname></para>
249           </listitem>
250
251           <listitem>
252             <para>improved: add option 'dates_as_objects' to
253             <function>php_xmlrpc_decode</function> to return
254             <classname>dateTime</classname> objects for xmlrpc
255             datetimes</para>
256           </listitem>
257
258           <listitem>
259             <para>improved: add new method
260             <methodname>SetCurlOptions</methodname> to
261             <classname>xmrlpc_client</classname> to allow extra flexibility in
262             tweaking http config, such as explicitly binding to an ip
263             address</para>
264           </listitem>
265
266           <listitem>
267             <para>improved: add new method
268             <methodname>SetUserAgent</methodname> to
269             <classname>xmrlpc_client</classname> to to allow having different
270             user-agent http headers</para>
271           </listitem>
272
273           <listitem>
274             <para>improved: add a new member variable in server class to allow
275             fine-tuning of the encoding of returned values when the server is
276             in 'phpvals' mode</para>
277           </listitem>
278
279           <listitem>
280             <para>improved: allow servers in 'xmlrpcvals' mode to also
281             register plain php functions by defining them in the dispatch map
282             with an added option</para>
283           </listitem>
284
285           <listitem>
286             <para>improved: catch exceptions thrown during execution of php
287             functions exposed as methods by the server</para>
288           </listitem>
289
290           <listitem>
291             <para>fixed: bad encoding if same object is encoded twice using
292             php_xmlrpc_encode</para>
293           </listitem>
294         </itemizedlist></para>
295     </sect1>
296
297     <sect1>
298       <title>2.2.2</title>
299
300       <para><emphasis>Note:</emphasis> this might the last release of the
301       library that will support PHP 4. Future releases (if any) should target
302       php 5.0 as minimum supported version.</para>
303
304       <para><itemizedlist>
305           <listitem>
306             <para>fixed: encoding of utf-8 characters outside of the BMP
307             plane</para>
308           </listitem>
309
310           <listitem>
311             <para>fixed: character set declarations surrounded by double
312             quotes were not recognized in http headers</para>
313           </listitem>
314
315           <listitem>
316             <para>fixed: be more tolerant in detection of charset in http
317             headers</para>
318           </listitem>
319
320           <listitem>
321             <para>fixed: fix detection of zlib.output_compression</para>
322           </listitem>
323
324           <listitem>
325             <para>fixed: use feof() to test if socket connections are to be
326             closed instead of the number of bytes read (rare bug when
327             communicating with some servers)</para>
328           </listitem>
329
330           <listitem>
331             <para>fixed: format floating point values using the correct
332             decimal separator even when php locale is set to one that uses
333             comma</para>
334           </listitem>
335
336           <listitem>
337             <para>fixed: improve robustness of the debugger when parsing weird
338             results from non-compliant servers</para>
339           </listitem>
340
341           <listitem>
342             <para>php warning when receiving 'false' in a bool value</para>
343           </listitem>
344
345           <listitem>
346             <para>improved: allow the add_to_map server method to add docs for
347             single params too</para>
348           </listitem>
349
350           <listitem>
351             <para>improved: added the possibility to wrap for exposure as
352             xmlrpc methods plain php class methods, object methods and even
353             whole classes</para>
354           </listitem>
355         </itemizedlist></para>
356     </sect1>
357
358     <sect1>
359       <title>2.2.1</title>
360
361       <itemizedlist>
362         <listitem>
363           <para>fixed: work aroung bug in php 5.2.2 which broke support of
364           HTTP_RAW_POST_DATA</para>
365         </listitem>
366
367         <listitem>
368           <para>fixed: is_dir parameter of setCaCertificate() method is
369           reversed</para>
370         </listitem>
371
372         <listitem>
373           <para>fixed: a php warning in xmlrpc_client creator method</para>
374         </listitem>
375
376         <listitem>
377           <para>fixed: parsing of '1e+1' as valid float</para>
378         </listitem>
379
380         <listitem>
381           <para>fixed: allow errorlevel 3 to work when prev. error handler was
382           a static method</para>
383         </listitem>
384
385         <listitem>
386           <para>fixed: usage of client::setcookie() for multiple cookies in
387           non-ssl mode</para>
388         </listitem>
389
390         <listitem>
391           <para>improved: support for CP1252 charset is not part or the
392           library but almost possible</para>
393         </listitem>
394
395         <listitem>
396           <para>improved: more info when curl is enabled and debug mode is
397           on</para>
398         </listitem>
399       </itemizedlist>
400     </sect1>
401
402     <sect1>
403       <title>2.2</title>
404
405       <itemizedlist>
406         <listitem>
407           <para>fixed: debugger errors on php installs with magic_quotes_gpc
408           on</para>
409         </listitem>
410
411         <listitem>
412           <para>fixed: support for https connections via proxy</para>
413         </listitem>
414
415         <listitem>
416           <para>fixed: wrap_xmlrpc_method() generated code failed to properly
417           encode php objects</para>
418         </listitem>
419
420         <listitem>
421           <para>improved: slightly faster encoding of data which is internally
422           UTF-8</para>
423         </listitem>
424
425         <listitem>
426           <para>improved: debugger always generates a 'null' id for jsonrpc if
427           user omits it</para>
428         </listitem>
429
430         <listitem>
431           <para>new: debugger can take advantage of a graphical value builder
432           (it has to be downloaded separately, as part of jsxmlrpc package.
433           See Appendix D for more details)</para>
434         </listitem>
435
436         <listitem>
437           <para>new: support for the &lt;NIL/&gt; xmlrpc extension. see below
438           for more details</para>
439         </listitem>
440
441         <listitem>
442           <para>new: server support for the system.getCapabilities xmlrpc
443           extension</para>
444         </listitem>
445
446         <listitem>
447           <para>new: <function><link
448           linkend="wrap_xmlrpc_method">wrap_xmlrpc_method()</link></function>
449           accepts two new options: debug and return_on_fault</para>
450         </listitem>
451       </itemizedlist>
452     </sect1>
453
454     <sect1>
455       <title>2.1</title>
456
457       <para><itemizedlist>
458           <listitem>
459             <para>The <function>wrap_php_function</function> and
460             <function>wrap_xmlrpc_method</function> functions have been moved
461             out of the base library file <filename>xmlrpc.inc</filename> into
462             a file of their own: <filename>xmlrpc_wrappers.inc</filename>. You
463             will have to include() / require() it in your scripts if you have
464             been using those functions. For increased security, the automatic
465             rebuilding of php object instances out of received xmlrpc structs
466             in <function>wrap_xmlrpc_method()</function> has been disabled
467             (but it can be optionally re-enabled). Both
468             <function>wrap_php_function()</function> and
469             <function>wrap_xmlrpc_method()</function> functions accept many
470             more options to fine tune their behaviour, including one to return
471             the php code to be saved and later used as standalone php
472             script</para>
473           </listitem>
474
475           <listitem>
476             <para>The constructor of xmlrpcval() values has seen some internal
477             changes, and it will not throw a php warning anymore when invoked
478             using an unknown xmlrpc type: the error will only be written to
479             php error log. Also <code>new xmlrpcval('true', 'boolean')</code>
480             is not supported anymore</para>
481           </listitem>
482
483           <listitem>
484             <para>The new function
485             <function>php_xmlrpc_decode_xml()</function> will take the xml
486             representation of either an xmlrpc request, response or single
487             value and return the corresponding php-xmlrpc object
488             instance</para>
489           </listitem>
490
491           <listitem>
492             <para>A new function <function>wrap_xmlrpc_server()</function>has
493             been added, to wrap all (or some) of the methods exposed by a
494             remote xmlrpc server into a php class</para>
495           </listitem>
496
497           <listitem>
498             <para>A new file has been added:
499             <filename>verify_compat.php</filename>, to help users diagnose the
500             level of compliance of their php installation with the
501             library</para>
502           </listitem>
503
504           <listitem>
505             <para>Restored compatibility with php 4.0.5 (for those poor souls
506             still stuck on it)</para>
507           </listitem>
508
509           <listitem>
510             <para>Method <methodname>xmlrpc_server-&gt;service()</methodname>
511             now returns a value: either the response payload or xmlrpcresp
512             object instance</para>
513           </listitem>
514
515           <listitem>
516             <para>Method
517             <methodname>xmlrpc_server-&gt;add_to_map()</methodname> now
518             accepts xmlrpc methods with no param definitions</para>
519           </listitem>
520
521           <listitem>
522             <para>Documentation for single parameters of exposed methods can
523             be added to the dispatch map (and turned into html docs in
524             conjunction with a future release of the 'extras' package)</para>
525           </listitem>
526
527           <listitem>
528             <para>Full response payload is saved into xmlrpcresp object for
529             further debugging</para>
530           </listitem>
531
532           <listitem>
533             <para>The debugger can now generate code that wraps a remote
534             method into a php function (works for jsonrpc, too); it also has
535             better support for being activated via a single GET call (e.g. for
536             integration into other tools)</para>
537           </listitem>
538
539           <listitem>
540             <para>Stricter parsing of incoming xmlrpc messages: two more
541             invalid cases are now detected (double <literal>data</literal>
542             element inside <literal>array</literal> and
543             <literal>struct</literal>/<literal>array</literal> after scalar
544             inside <literal>value</literal> element)</para>
545           </listitem>
546
547           <listitem>
548             <para>More logging of errors in a lot of situations</para>
549           </listitem>
550
551           <listitem>
552             <para>Javadoc documentation of lib files (almost) complete</para>
553           </listitem>
554
555           <listitem>
556             <para>Many performance tweaks and code cleanups, plus the usual
557             crop of bugs fixed (see NEWS file for complete list of
558             bugs)</para>
559           </listitem>
560
561           <listitem>
562             <para>Lib internals have been modified to provide better support
563             for grafting extra functionality on top of it. Stay tuned for
564             future releases of the EXTRAS package (or go read Appendix
565             B)...</para>
566           </listitem>
567         </itemizedlist></para>
568     </sect1>
569
570     <sect1>
571       <title>2.0 final</title>
572
573       <para><itemizedlist>
574           <listitem>
575             <para>Added to the client class the possibility to use Digest and
576             NTLM authentication methods (when using the CURL library) for
577             connecting to servers and NTLM for connecting to proxies</para>
578           </listitem>
579
580           <listitem>
581             <para>Added to the client class the possibility to specify
582             alternate certificate files/directories for authenticating the
583             peer with when using HTTPS communication</para>
584           </listitem>
585
586           <listitem>
587             <para>Reviewed all examples and added a new demo file, containing
588             a proxy to forward xmlrpc requests to other servers (useful e.g.
589             for ajax coding)</para>
590           </listitem>
591
592           <listitem>
593             <para>The debugger has been upgraded to reflect the new client
594             capabilities</para>
595           </listitem>
596
597           <listitem>
598             <para>All known bugs have been squashed, and the lib is more
599             tolerant than ever of commonly-found mistakes</para>
600           </listitem>
601         </itemizedlist></para>
602     </sect1>
603
604     <sect1>
605       <title>2.0 Release candidate 3</title>
606
607       <para><itemizedlist>
608           <listitem>
609             <para>Added to server class the property
610             <property>functions_parameters_type</property>, that allows the
611             server to register plain php functions as xmlrpc methods (i.e.
612             functions that do not take an xmlrpcmsg object as unique
613             param)</para>
614           </listitem>
615
616           <listitem>
617             <para>let server and client objects serialize calls using a
618             specified character set encoding for the produced xml instead of
619             US-ASCII (ISO-8859-1 and UTF-8 supported)</para>
620           </listitem>
621
622           <listitem>
623             <para>let php_xmlrpc_decode accept xmlrpcmsg objects as valid
624             input</para>
625           </listitem>
626
627           <listitem>
628             <para>'class::method' syntax is now accepted in the server
629             dispatch map</para>
630           </listitem>
631
632           <listitem>
633             <para><function>xmlrpc_clent::SetDebug()</function> accepts
634             integer values instead of a boolean value, with debugging level 2
635             adding to the information printed to screen the complete client
636             request</para>
637           </listitem>
638         </itemizedlist></para>
639     </sect1>
640
641     <sect1>
642       <title>2.0 Release candidate 2</title>
643
644       <para><itemizedlist>
645           <listitem>
646             <para>Added a new property of the client object:
647             <code>xmlrpc_client-&gt;return_type</code>, indicating whether
648             calls to the send() method will return xmlrpcresp objects whose
649             value() is an xmlrpcval object, a php value (automatically
650             decoded) or the raw xml received from the server.</para>
651           </listitem>
652
653           <listitem>
654             <para>Added in the extras dir. two new library file:
655             <filename>jsonrpc.inc</filename> and
656             <filename>jsonrpcs.inc</filename> containing new classes that
657             implement support for the json-rpc protocol (alpha quality
658             code)</para>
659           </listitem>
660
661           <listitem>
662             <para>Added a new client method: <code>setKey($key,
663             $keypass)</code> to be used in HTTPS connections</para>
664           </listitem>
665
666           <listitem>
667             <para>Added a new file containing some benchmarks in the testsuite
668             directory</para>
669           </listitem>
670         </itemizedlist></para>
671     </sect1>
672
673     <sect1>
674       <title>2.0 Release candidate 1</title>
675
676       <itemizedlist>
677         <listitem>
678           <para>Support for HTTP proxies (new method:
679           <code>xmlrpc_client::setProxy()</code>)</para>
680         </listitem>
681
682         <listitem>
683           <para>Support HTTP compression of both requests and responses.
684           Clients can specify what kind of compression they accept for
685           responses between deflate/gzip/any, and whether to compress the
686           requests. Servers by default compress responses to clients that
687           explicitly declare support for compression (new methods:
688           <code>xmlrpc_client::setAcceptedCompression()</code>,
689           <code>xmlrpc_client::setRequestCompression()</code>). Note that the
690           ZLIB php extension needs to be enabled in PHP to support
691           compression.</para>
692         </listitem>
693
694         <listitem>
695           <para>Implement HTTP 1.1 connections, but only if CURL is enabled
696           (added an extra parameter to
697           <code>xmlrpc_client::xmlrpc_client</code> to set the desired HTTP
698           protocol at creation time and a new supported value for the last
699           parameter of <code>xmlrpc_client::send</code>, which now can be
700           safely omitted if it has been specified at creation time)</para>
701
702           <para>With PHP versions greater than 4.3.8 keep-alives are enabled
703           by default for HTTP 1.1 connections. This should yield faster
704           execution times when making multiple calls in sequence to the same
705           xml-rpc server from a single client.</para>
706         </listitem>
707
708         <listitem>
709           <para>Introduce support for cookies. Cookies to be sent to the
710           server with a request can be set using
711           <code>xmlrpc_client::setCookie()</code>, while cookies received from
712           the server are found in <code>xmlrpcresp::cookies()</code>. It is
713           left to the user to check for validity of received cookies and
714           decide whether they apply to successive calls or not.</para>
715         </listitem>
716
717         <listitem>
718           <para>Better support for detecting different character set encodings
719           of xml-rpc requests and responses: both client and server objects
720           will correctly detect the charset encoding of received xml, and use
721           an appropriate xml parser.</para>
722
723           <para>Supported encodings are US-ASCII, UTF-8 and ISO-8859-1.</para>
724         </listitem>
725
726         <listitem>
727           <para>Added one new xmlrpcmsg constructor syntax, allowing usage of
728           a single string with the complete URL of the target server</para>
729         </listitem>
730
731         <listitem>
732           <para>Convert xml-rpc boolean values into native php values instead
733           of 0 and 1</para>
734         </listitem>
735
736         <listitem>
737           <para>Force the <code>php_xmlrpc_encode</code> function to properly
738           encode numerically indexed php arrays into xml-rpc arrays
739           (numerically indexed php arrays always start with a key of 0 and
740           increment keys by values of 1)</para>
741         </listitem>
742
743         <listitem>
744           <para>Prevent the <code>php_xmlrpc_encode</code> function from
745           further re-encoding any objects of class <code>xmlrpcval</code> that
746           are passed to it. This allows to call the function with arguments
747           consisting of mixed php values / xmlrpcval objects.</para>
748         </listitem>
749
750         <listitem>
751           <para>Allow a server to NOT respond to system.* method calls
752           (setting the <code>$server-&gt;allow_system_funcs</code>
753           property).</para>
754         </listitem>
755
756         <listitem>
757           <para>Implement a new xmlrpcval method to determine if a value of
758           type struct has a member of a given name without having to loop
759           trough all members: <code>xmlrpcval::structMemExists()</code></para>
760         </listitem>
761
762         <listitem>
763           <para>Expand methods <code>xmlrpcval::addArray</code>,
764           <code>addScalar</code> and <code>addStruct</code> allowing extra php
765           values to be added to xmlrpcval objects already formed.</para>
766         </listitem>
767
768         <listitem>
769           <para>Let the <code>xmlrpc_client::send</code> method accept an XML
770           string for sending instead of an xmlrpcmsg object, to facilitate
771           debugging and integration with the php native xmlrpc
772           extension</para>
773         </listitem>
774
775         <listitem>
776           <para>Extend the <code>php_xmlrpc_encode</code> and
777           <code>php_xmlrpc_decode</code> functions to allow serialization and
778           rebuilding of PHP objects. To successfully rebuild a serialized
779           object, the object class must be defined in the deserializing end of
780           the transfer. Note that object members of type resource will be
781           deserialized as NULL values.</para>
782
783           <para>Note that his has been implemented adding a "php_class"
784           attribute to xml representation of xmlrpcval of STRUCT type, which,
785           strictly speaking, breaks the xml-rpc spec. Other xmlrpc
786           implementations are supposed to ignore such an attribute (unless
787           they implement a brain-dead custom xml parser...), so it should be
788           safe enabling it in heterogeneous environments. The activation of
789           this feature is done by usage of an option passed as second
790           parameter to both <code>php_xmlrpc_encode</code> and
791           <code>php_xmlrpc_decode</code>.</para>
792         </listitem>
793
794         <listitem>
795           <para>Extend the <code>php_xmlrpc_encode</code> function to allow
796           automatic serialization of iso8601-conforming php strings as
797           datetime.iso8601 xmlrpcvals, by usage of an optional
798           parameter</para>
799         </listitem>
800
801         <listitem>
802           <para>Added an automatic stub code generator for converting xmlrpc
803           methods to php functions and vice-versa.</para>
804
805           <para>This is done via two new functions:
806           <code>wrap_php_function</code> and <code>wrap_xmlrpc_method</code>,
807           and has many caveats, with php being a typeless language and
808           all...</para>
809
810           <para>With PHP versions lesser than 5.0.3 wrapping of php functions
811           into xmlrpc methods is not supported yet.</para>
812         </listitem>
813
814         <listitem>
815           <para>Allow object methods to be used in server dispatch map</para>
816         </listitem>
817
818         <listitem>
819           <para>Added a complete debugger solution, in the
820           <filename>debugger</filename> folder</para>
821         </listitem>
822
823         <listitem>
824           <para>Added configurable server-side debug messages, controlled by
825           the new method <code>xmlrpc_server::SetDebug()</code>. At level 0,
826           no debug messages are sent to the client; level 1 is the same as the
827           old behaviour; at level 2 a lot more info is echoed back to the
828           client, regarding the received call; at level 3 all warnings raised
829           during server processing are trapped (this prevents breaking the xml
830           to be echoed back to the client) and added to the debug info sent
831           back to the client</para>
832         </listitem>
833
834         <listitem>
835           <para>New XML parsing code, yields smaller memory footprint and
836           faster execution times, not to mention complete elimination of the
837           dreaded <filename>eval()</filename> construct, so prone to code
838           injection exploits</para>
839         </listitem>
840
841         <listitem>
842           <para>Rewritten most of the error messages, making text more
843           explicative</para>
844         </listitem>
845       </itemizedlist>
846     </sect1>
847   </chapter>
848
849   <chapter id="requirements">
850     <title>System Requirements</title>
851
852     <para>The library has been designed with goals of scalability and backward
853     compatibility. As such, it supports a wide range of PHP installs. Note
854     that not all features of the lib are available in every
855     configuration.</para>
856
857     <para>The <emphasis>minimum supported</emphasis> PHP version is
858     5.0.</para>
859
860     <para>Automatic generation of xml-rpc methods from php functions is only
861     supported with PHP version 5.0.3 and later (note that the lib will
862     generate some warnings with PHP 5 in strict error reporting mode).</para>
863
864     <para>If you wish to use SSL or HTTP 1.1 to communicate with remote
865     servers, you need the "curl" extension compiled into your PHP
866     installation.</para>
867
868     <para>The "xmlrpc" native extension is not required to be compiled into
869     your PHP installation, but if it is, there will be no interference with
870     the operation of this library.</para>
871   </chapter>
872
873   <chapter id="manifest">
874     <title>Files in the distribution</title>
875
876     <glosslist>
877       <glossentry>
878         <glossterm>lib/xmlrpc.inc</glossterm>
879
880         <glossdef>
881           <para>the XML-RPC classes. <function>include()</function> this in
882           your PHP files to use the classes.</para>
883         </glossdef>
884       </glossentry>
885
886       <glossentry>
887         <glossterm>lib/xmlrpcs.inc</glossterm>
888
889         <glossdef>
890           <para>the XML-RPC server class. <function>include()</function> this
891           in addition to xmlrpc.inc to get server functionality</para>
892         </glossdef>
893       </glossentry>
894
895       <glossentry>
896         <glossterm>lib/xmlrpc_wrappers.inc</glossterm>
897
898         <glossdef>
899           <para>helper functions to "automagically" convert plain php
900           functions to xmlrpc services and vice versa</para>
901         </glossdef>
902       </glossentry>
903
904       <glossentry>
905         <glossterm>demo/server/proxy.php</glossterm>
906
907         <glossdef>
908           <para>a sample server implementing xmlrpc proxy
909           functionality.</para>
910         </glossdef>
911       </glossentry>
912
913       <glossentry>
914         <glossterm>demo/server/server.php</glossterm>
915
916         <glossdef>
917           <para>a sample server hosting various demo functions, as well as a
918           full suite of functions used for interoperability testing. It is
919           used by testsuite.php (see below) for unit testing the library, and
920           is not to be copied literally into your production servers</para>
921         </glossdef>
922       </glossentry>
923
924       <glossentry>
925         <glossterm>demo/client/client.php, demo/client/agesort.php,
926         demo/client/which.php</glossterm>
927
928         <glossdef>
929           <para>client code to exercise some of the functions in server.php,
930           including the <function>interopEchoTests.whichToolkit</function>
931           method.</para>
932         </glossdef>
933       </glossentry>
934
935       <glossentry>
936         <glossterm>demo/client/wrap.php</glossterm>
937
938         <glossdef>
939           <para>client code to illustrate 'wrapping' of remote methods into
940           php functions.</para>
941         </glossdef>
942       </glossentry>
943
944       <glossentry>
945         <glossterm>demo/client/introspect.php</glossterm>
946
947         <glossdef>
948           <para>client code to illustrate usage of introspection capabilities
949           offered by server.php.</para>
950         </glossdef>
951       </glossentry>
952
953       <glossentry>
954         <glossterm>demo/client/mail.php</glossterm>
955
956         <glossdef>
957           <para>client code to illustrate usage of an xmlrpc-to-email gateway
958           using Dave Winer's XML-RPC server at userland.com.</para>
959         </glossdef>
960       </glossentry>
961
962       <glossentry>
963         <glossterm>demo/client/zopetest.php</glossterm>
964
965         <glossdef>
966           <para>example client code that queries an xmlrpc server built in
967           Zope.</para>
968         </glossdef>
969       </glossentry>
970
971       <glossentry>
972         <glossterm>demo/vardemo.php</glossterm>
973
974         <glossdef>
975           <para>examples of how to construct xmlrpcval types</para>
976         </glossdef>
977       </glossentry>
978
979       <glossentry>
980         <glossterm>demo/demo1.txt, demo/demo2.txt, demo/demo3.txt</glossterm>
981
982         <glossdef>
983           <para>XML-RPC responses captured in a file for testing purposes (you
984           can use these to test the
985           <function>xmlrpcmsg-&gt;parseResponse()</function> method).</para>
986         </glossdef>
987       </glossentry>
988
989       <glossentry>
990         <glossterm>demo/server/discuss.php,
991         demo/client/comment.php</glossterm>
992
993         <glossdef>
994           <para>Software used in the PHP chapter of <xref
995           linkend="jellyfish" /> to provide a comment server and allow the
996           attachment of comments to stories from Meerkat's data store.</para>
997         </glossdef>
998       </glossentry>
999
1000       <glossentry>
1001         <glossterm>test/testsuite.php, test/parse_args.php</glossterm>
1002
1003         <glossdef>
1004           <para>A unit test suite for this software package. If you do
1005           development on this software, please consider submitting tests for
1006           this suite.</para>
1007         </glossdef>
1008       </glossentry>
1009
1010       <glossentry>
1011         <glossterm>test/benchmark.php</glossterm>
1012
1013         <glossdef>
1014           <para>A (very limited) benchmarking suite for this software package.
1015           If you do development on this software, please consider submitting
1016           benchmarks for this suite.</para>
1017         </glossdef>
1018       </glossentry>
1019
1020       <glossentry>
1021         <glossterm>test/phpunit.php, test/PHPUnit/*.php</glossterm>
1022
1023         <glossdef>
1024           <para>An (incomplete) version PEAR's unit test framework for PHP.
1025           The complete package can be found at <ulink
1026           url="http://pear.php.net/package/PHPUnit">http://pear.php.net/package/PHPUnit</ulink></para>
1027         </glossdef>
1028       </glossentry>
1029
1030       <glossentry>
1031         <glossterm>test/verify_compat.php</glossterm>
1032
1033         <glossdef>
1034           <para>Script designed to help the user to verify the level of
1035           compatibility of the library with the current php install</para>
1036         </glossdef>
1037       </glossentry>
1038
1039       <glossentry>
1040         <glossterm>extras/test.pl, extras/test.py</glossterm>
1041
1042         <glossdef>
1043           <para>Perl and Python programs to exercise server.php to test that
1044           some of the methods work.</para>
1045         </glossdef>
1046       </glossentry>
1047
1048       <glossentry>
1049         <glossterm>extras/workspace.testPhpServer.fttb</glossterm>
1050
1051         <glossdef>
1052           <para>Frontier scripts to exercise the demo server. Thanks to Dave
1053           Winer for permission to include these. See <ulink
1054           url="http://www.xmlrpc.com/discuss/msgReader$853">Dave's
1055           announcement of these.</ulink></para>
1056         </glossdef>
1057       </glossentry>
1058
1059       <glossentry>
1060         <glossterm>extras/rsakey.pem</glossterm>
1061
1062         <glossdef>
1063           <para>A test certificate key for the SSL support, which can be used
1064           to generate dummy certificates. It has the passphrase "test."</para>
1065         </glossdef>
1066       </glossentry>
1067     </glosslist>
1068   </chapter>
1069
1070   <chapter id="bugs">
1071     <title>Known bugs and limitations</title>
1072
1073     <para>This started out as a bare framework. Many "nice" bits haven't been
1074     put in yet. Specifically, very little type validation or coercion has been
1075     put in. PHP being a loosely-typed language, this is going to have to be
1076     done explicitly (in other words: you can call a lot of library functions
1077     passing them arguments of the wrong type and receive an error message only
1078     much further down the code, where it will be difficult to
1079     understand).</para>
1080
1081     <para>dateTime.iso8601 is supported opaquely. It can't be done natively as
1082     the XML-RPC specification explicitly forbids passing of timezone
1083     specifiers in ISO8601 format dates. You can, however, use the <xref
1084     linkend="iso8601encode" /> and <xref linkend="iso8601decode" /> functions
1085     to do the encoding and decoding for you.</para>
1086
1087     <para>Very little HTTP response checking is performed (e.g. HTTP redirects
1088     are not followed and the Content-Length HTTP header, mandated by the
1089     xml-rpc spec, is not validated); cookie support still involves quite a bit
1090     of coding on the part of the user.</para>
1091
1092     <para>If a specific character set encoding other than US-ASCII, ISO-8859-1
1093     or UTF-8 is received in the HTTP header or XML prologue of xml-rpc request
1094     or response messages then it will be ignored for the moment, and the
1095     content will be parsed as if it had been encoded using the charset defined
1096     by <xref linkend="xmlrpc-defencoding" /></para>
1097
1098     <para>Support for receiving from servers version 1 cookies (i.e.
1099     conforming to RFC 2965) is quite incomplete, and might cause unforeseen
1100     errors.</para>
1101   </chapter>
1102
1103   <chapter id="support">
1104     <title>Support</title>
1105
1106     <sect1>
1107       <title>Online Support</title>
1108
1109       <para>XML-RPC for PHP is offered "as-is" without any warranty or
1110       commitment to support. However, informal advice and help is available
1111       via the XML-RPC for PHP website and mailing list and from
1112       XML-RPC.com.</para>
1113
1114       <itemizedlist>
1115         <listitem>
1116           <para>The <emphasis>XML-RPC for PHP</emphasis> development is hosted
1117           on <ulink
1118           url="http://phpxmlrpc.sourceforge.net">phpxmlrpc.sourceforge.net</ulink>.
1119           Bugs, feature requests and patches can be posted to the <ulink
1120           url="http://sourceforge.net/projects/phpxmlrpc">project's
1121           website</ulink>.</para>
1122         </listitem>
1123
1124         <listitem>
1125           <para>The <emphasis>PHP XML-RPC interest mailing list</emphasis> is
1126           run by the author. More details <ulink
1127           url="http://lists.gnomehack.com/mailman/listinfo/phpxmlrpc">can be
1128           found here</ulink>.</para>
1129         </listitem>
1130
1131         <listitem>
1132           <para>For more general XML-RPC questions, there is a Yahoo! Groups
1133           <ulink url="http://groups.yahoo.com/group/xml-rpc/">XML-RPC mailing
1134           list</ulink>.</para>
1135         </listitem>
1136
1137         <listitem>
1138           <para>The <ulink
1139           url="http://www.xmlrpc.com/discuss">XML-RPC.com</ulink> discussion
1140           group is a useful place to get help with using XML-RPC. This group
1141           is also gatewayed into the Yahoo! Groups mailing list.</para>
1142         </listitem>
1143       </itemizedlist>
1144     </sect1>
1145
1146     <sect1 id="jellyfish" xreflabel="The Jellyfish Book">
1147       <title>The Jellyfish Book</title>
1148
1149       <para><graphic align="right" depth="190" fileref="progxmlrpc.s.gif"
1150       format="GIF" width="145" />Together with Simon St.Laurent and Joe
1151       Johnston, Edd Dumbill wrote a book on XML-RPC for O'Reilly and
1152       Associates on XML-RPC. It features a rather fetching jellyfish on the
1153       cover.</para>
1154
1155       <para>Complete details of the book are <ulink
1156       url="http://www.oreilly.com/catalog/progxmlrpc/">available from
1157       O'Reilly's web site.</ulink></para>
1158
1159       <para>Edd is responsible for the chapter on PHP, which includes a worked
1160       example of creating a forum server, and hooking it up the O'Reilly's
1161       <ulink url="http://meerkat.oreillynet.com/">Meerkat</ulink> service in
1162       order to allow commenting on news stories from around the Web.</para>
1163
1164       <para>If you've benefited from the effort that has been put into writing
1165       this software, then please consider buying the book!</para>
1166     </sect1>
1167   </chapter>
1168
1169   <chapter id="apidocs">
1170     <title>Class documentation</title>
1171
1172     <sect1 id="xmlrpcval" xreflabel="xmlrpcval">
1173       <title>xmlrpcval</title>
1174
1175       <para>This is where a lot of the hard work gets done. This class enables
1176       the creation and encapsulation of values for XML-RPC.</para>
1177
1178       <para>Ensure you've read the XML-RPC spec at <ulink
1179       url="http://www.xmlrpc.com/stories/storyReader$7">http://www.xmlrpc.com/stories/storyReader$7</ulink>
1180       before reading on as it will make things clearer.</para>
1181
1182       <para>The <classname>xmlrpcval</classname> class can store arbitrarily
1183       complicated values using the following types: <literal>i4 int boolean
1184       string double dateTime.iso8601 base64 array struct</literal>
1185       <literal>null</literal>. You should refer to the <ulink
1186       url="http://www.xmlrpc.com/spec">spec</ulink> for more information on
1187       what each of these types mean.</para>
1188
1189       <sect2>
1190         <title>Notes on types</title>
1191
1192         <sect3>
1193           <title>int</title>
1194
1195           <para>The type <classname>i4</classname> is accepted as a synonym
1196           for <classname>int</classname> when creating xmlrpcval objects. The
1197           xml parsing code will always convert <classname>i4</classname> to
1198           <classname>int</classname>: <classname>int</classname> is regarded
1199           by this implementation as the canonical name for this type.</para>
1200         </sect3>
1201
1202         <sect3>
1203           <title>base64</title>
1204
1205           <para>Base 64 encoding is performed transparently to the caller when
1206           using this type. Decoding is also transparent. Therefore you ought
1207           to consider it as a "binary" data type, for use when you want to
1208           pass data that is not 7-bit clean.</para>
1209         </sect3>
1210
1211         <sect3>
1212           <title>boolean</title>
1213
1214           <para>The php values <literal>true</literal> and
1215           <literal>1</literal> map to <literal>true</literal>. All other
1216           values (including the empty string) are converted to
1217           <literal>false</literal>.</para>
1218         </sect3>
1219
1220         <sect3>
1221           <title>string</title>
1222
1223           <para>Characters &lt;, &gt;, ', ", &amp;, are encoded using their
1224           entity reference as &amp;lt; &amp;gt; &amp;apos; &amp;quot; and
1225           &amp;amp; All other characters outside of the ASCII range are
1226           encoded using their character reference representation (e.g.
1227           &amp;#200 for é). The XML-RPC spec recommends only encoding
1228           <literal>&lt; &amp;</literal> but this implementation goes further,
1229           for reasons explained by <ulink
1230           url="http://www.w3.org/TR/REC-xml#syntax">the XML 1.0
1231           recommendation</ulink>. In particular, using character reference
1232           representation has the advantage of producing XML that is valid
1233           independently of the charset encoding assumed.</para>
1234         </sect3>
1235
1236         <sect3>
1237           <title>null</title>
1238
1239           <para>There is no support for encoding <literal>null</literal>
1240           values in the XML-RPC spec, but at least a couple of extensions (and
1241           many toolkits) do support it. Before using <literal>null</literal>
1242           values in your messages, make sure that the responding party accepts
1243           them, and uses the same encoding convention (see ...).</para>
1244         </sect3>
1245       </sect2>
1246
1247       <sect2 id="xmlrpcval-creation" xreflabel="xmlrpcval constructors">
1248         <title>Creation</title>
1249
1250         <para>The constructor is the normal way to create an
1251         <classname>xmlrpcval</classname>. The constructor can take these
1252         forms:</para>
1253
1254         <funcsynopsis>
1255           <funcprototype>
1256             <funcdef><type>xmlrpcval</type>new
1257             <function>xmlrpcval</function></funcdef>
1258
1259             <void />
1260           </funcprototype>
1261
1262           <funcprototype>
1263             <funcdef><type>xmlrpcval</type>new
1264             <function>xmlrpcval</function></funcdef>
1265
1266             <paramdef><type>string</type><parameter>$stringVal</parameter></paramdef>
1267           </funcprototype>
1268
1269           <funcprototype>
1270             <funcdef><type>xmlrpcval</type>new
1271             <function>xmlrpcval</function></funcdef>
1272
1273             <paramdef><type>mixed</type><parameter>$scalarVal</parameter></paramdef>
1274
1275             <paramdef><type>string</type><parameter>$scalartyp</parameter></paramdef>
1276           </funcprototype>
1277
1278           <funcprototype>
1279             <funcdef><type>xmlrpcval</type>new
1280             <function>xmlrpcval</function></funcdef>
1281
1282             <paramdef><type>array</type><parameter>$arrayVal</parameter></paramdef>
1283
1284             <paramdef><type>string</type><parameter>$arraytyp</parameter></paramdef>
1285           </funcprototype>
1286         </funcsynopsis>
1287
1288         <para>The first constructor creates an empty value, which must be
1289         altered using the methods <function>addScalar</function>,
1290         <function>addArray</function> or <function>addStruct</function> before
1291         it can be used.</para>
1292
1293         <para>The second constructor creates a simple string value.</para>
1294
1295         <para>The third constructor is used to create a scalar value. The
1296         second parameter must be a name of an XML-RPC type. Valid types are:
1297         "<literal>int</literal>", "<literal>boolean</literal>",
1298         "<literal>string</literal>", "<literal>double</literal>",
1299         "<literal>dateTime.iso8601</literal>", "<literal>base64</literal>" or
1300         "null".</para>
1301
1302         <para>Examples:</para>
1303
1304         <programlisting language="php">
1305 $myInt = new xmlrpcvalue(1267, "int");
1306 $myString = new xmlrpcvalue("Hello, World!", "string");
1307 $myBool = new xmlrpcvalue(1, "boolean");
1308 $myString2 = new xmlrpcvalue(1.24, "string"); // note: this will serialize a php float value as xmlrpc string
1309 </programlisting>
1310
1311         <para>The fourth constructor form can be used to compose complex
1312         XML-RPC values. The first argument is either a simple array in the
1313         case of an XML-RPC <classname>array</classname> or an associative
1314         array in the case of a <classname>struct</classname>. The elements of
1315         the array <emphasis>must be <classname>xmlrpcval</classname> objects
1316         themselves</emphasis>.</para>
1317
1318         <para>The second parameter must be either "<literal>array</literal>"
1319         or "<literal>struct</literal>".</para>
1320
1321         <para>Examples:</para>
1322
1323         <programlisting language="php">
1324 $myArray = new xmlrpcval(
1325   array(
1326     new xmlrpcval("Tom"),
1327     new xmlrpcval("Dick"),
1328     new xmlrpcval("Harry")
1329   ),
1330   "array");
1331
1332 // recursive struct
1333 $myStruct = new xmlrpcval(
1334   array(
1335     "name" =&gt; new xmlrpcval("Tom", "string"),
1336     "age" =&gt; new xmlrpcval(34, "int"),
1337     "address" =&gt; new xmlrpcval(
1338       array(
1339         "street" =&gt; new xmlrpcval("Fifht Ave", "string"),
1340         "city" =&gt; new xmlrpcval("NY", "string")
1341       ), 
1342       "struct")
1343   ), 
1344   "struct");
1345 </programlisting>
1346
1347         <para>See the file <literal>vardemo.php</literal> in this distribution
1348         for more examples.</para>
1349       </sect2>
1350
1351       <sect2 id="xmlrpcval-methods" xreflabel="xmlrpcval methods">
1352         <title>Methods</title>
1353
1354         <sect3>
1355           <title>addScalar</title>
1356
1357           <funcsynopsis>
1358             <funcprototype>
1359               <funcdef><type>int</type><function>addScalar</function></funcdef>
1360
1361               <paramdef><type>string</type><parameter>$stringVal</parameter></paramdef>
1362             </funcprototype>
1363
1364             <funcprototype>
1365               <funcdef><type>int</type><function>addScalar</function></funcdef>
1366
1367               <paramdef><type>mixed</type><parameter>$scalarVal</parameter></paramdef>
1368
1369               <paramdef><type>string</type><parameter>$scalartyp</parameter></paramdef>
1370             </funcprototype>
1371           </funcsynopsis>
1372
1373           <para>If <parameter>$val</parameter> is an empty
1374           <classname>xmlrpcval</classname> this method makes it a scalar
1375           value, and sets that value.</para>
1376
1377           <para>If <parameter>$val</parameter> is already a scalar value, then
1378           no more scalars can be added and <literal>0</literal> is
1379           returned.</para>
1380
1381           <para>If <parameter>$val</parameter> is an xmlrpcval of type array,
1382           the php value <parameter>$scalarval</parameter> is added as its last
1383           element.</para>
1384
1385           <para>If all went OK, <literal>1</literal> is returned, otherwise
1386           <literal>0</literal>.</para>
1387         </sect3>
1388
1389         <sect3>
1390           <title>addArray</title>
1391
1392           <funcsynopsis>
1393             <funcprototype>
1394               <funcdef><type>int</type><function>addArray</function></funcdef>
1395
1396               <paramdef><type>array</type><parameter>$arrayVal</parameter></paramdef>
1397             </funcprototype>
1398           </funcsynopsis>
1399
1400           <para>The argument is a simple (numerically indexed) array. The
1401           elements of the array <emphasis>must be
1402           <classname>xmlrpcval</classname> objects
1403           themselves</emphasis>.</para>
1404
1405           <para>Turns an empty <classname>xmlrpcval</classname> into an
1406           <classname>array</classname> with contents as specified by
1407           <parameter>$arrayVal</parameter>.</para>
1408
1409           <para>If <parameter>$val</parameter> is an xmlrpcval of type array,
1410           the elements of <parameter>$arrayVal</parameter> are appended to the
1411           existing ones.</para>
1412
1413           <para>See the fourth constructor form for more information.</para>
1414
1415           <para>If all went OK, <literal>1</literal> is returned, otherwise
1416           <literal>0</literal>.</para>
1417         </sect3>
1418
1419         <sect3>
1420           <title>addStruct</title>
1421
1422           <funcsynopsis>
1423             <funcprototype>
1424               <funcdef><type>int</type><function>addStruct</function></funcdef>
1425
1426               <paramdef><type>array</type><parameter>$assocArrayVal</parameter></paramdef>
1427             </funcprototype>
1428           </funcsynopsis>
1429
1430           <para>The argument is an associative array. The elements of the
1431           array <emphasis>must be <classname>xmlrpcval</classname> objects
1432           themselves</emphasis>.</para>
1433
1434           <para>Turns an empty <classname>xmlrpcval</classname> into a
1435           <classname>struct</classname> with contents as specified by
1436           <parameter>$assocArrayVal</parameter>.</para>
1437
1438           <para>If <parameter>$val</parameter> is an xmlrpcval of type struct,
1439           the elements of <parameter>$arrayVal</parameter> are merged with the
1440           existing ones.</para>
1441
1442           <para>See the fourth constructor form for more information.</para>
1443
1444           <para>If all went OK, <literal>1</literal> is returned, otherwise
1445           <literal>0</literal>.</para>
1446         </sect3>
1447
1448         <sect3>
1449           <title>kindOf</title>
1450
1451           <funcsynopsis>
1452             <funcprototype>
1453               <funcdef><type>string</type><function>kindOf</function></funcdef>
1454
1455               <void />
1456             </funcprototype>
1457           </funcsynopsis>
1458
1459           <para>Returns a string containing "struct", "array" or "scalar"
1460           describing the base type of the value. If it returns "undef" it
1461           means that the value hasn't been initialised.</para>
1462         </sect3>
1463
1464         <sect3>
1465           <title>serialize</title>
1466
1467           <funcsynopsis>
1468             <funcprototype>
1469               <funcdef><type>string</type><function>serialize</function></funcdef>
1470
1471               <void />
1472             </funcprototype>
1473           </funcsynopsis>
1474
1475           <para>Returns a string containing the XML-RPC representation of this
1476           value.</para>
1477         </sect3>
1478
1479         <sect3>
1480           <title>scalarVal</title>
1481
1482           <funcsynopsis>
1483             <funcprototype>
1484               <funcdef><type>mixed</type><function>scalarVal</function></funcdef>
1485
1486               <void />
1487             </funcprototype>
1488           </funcsynopsis>
1489
1490           <para>If <function>$val-&gt;kindOf() == "scalar"</function>, this
1491           method returns the actual PHP-language value of the scalar (base 64
1492           decoding is automatically handled here).</para>
1493         </sect3>
1494
1495         <sect3>
1496           <title>scalarTyp</title>
1497
1498           <funcsynopsis>
1499             <funcprototype>
1500               <funcdef><type>string</type><function>scalarTyp</function></funcdef>
1501
1502               <void />
1503             </funcprototype>
1504           </funcsynopsis>
1505
1506           <para>If <function>$val-&gt;kindOf() == "scalar"</function>, this
1507           method returns a string denoting the type of the scalar. As
1508           mentioned before, <literal>i4</literal> is always coerced to
1509           <literal>int</literal>.</para>
1510         </sect3>
1511
1512         <sect3>
1513           <title>arrayMem</title>
1514
1515           <funcsynopsis>
1516             <funcprototype>
1517               <funcdef><type>xmlrpcval</type><function>arrayMem</function></funcdef>
1518
1519               <paramdef><type>int</type><parameter>$n</parameter></paramdef>
1520             </funcprototype>
1521           </funcsynopsis>
1522
1523           <para>If <function>$val-&gt;kindOf() == "array"</function>, returns
1524           the <parameter>$n</parameter>th element in the array represented by
1525           the value <parameter>$val</parameter>. The value returned is an
1526           <classname>xmlrpcval</classname> object.</para>
1527
1528           <para><programlisting language="php">
1529 // iterating over values of an array object
1530 for ($i = 0; $i &lt; $val-&gt;arraySize(); $i++)
1531 {
1532   $v = $val-&gt;arrayMem($i);
1533   echo "Element $i of the array is of type ".$v-&gt;kindOf();
1534 }
1535 </programlisting></para>
1536         </sect3>
1537
1538         <sect3>
1539           <title>arraySize</title>
1540
1541           <funcsynopsis>
1542             <funcprototype>
1543               <funcdef><type>int</type><function>arraySize</function></funcdef>
1544
1545               <void />
1546             </funcprototype>
1547           </funcsynopsis>
1548
1549           <para>If <parameter>$val</parameter> is an
1550           <classname>array</classname>, returns the number of elements in that
1551           array.</para>
1552         </sect3>
1553
1554         <sect3>
1555           <title>structMem</title>
1556
1557           <funcsynopsis>
1558             <funcprototype>
1559               <funcdef><type>xmlrpcval</type><function>structMem</function></funcdef>
1560
1561               <paramdef><type>string</type><parameter>$memberName</parameter></paramdef>
1562             </funcprototype>
1563           </funcsynopsis>
1564
1565           <para>If <function>$val-&gt;kindOf() == "struct"</function>, returns
1566           the element called <parameter>$memberName</parameter> from the
1567           struct represented by the value <parameter>$val</parameter>. The
1568           value returned is an <classname>xmlrpcval</classname> object.</para>
1569         </sect3>
1570
1571         <sect3>
1572           <title>structEach</title>
1573
1574           <funcsynopsis>
1575             <funcprototype>
1576               <funcdef><type>array</type><function>structEach</function></funcdef>
1577
1578               <void />
1579             </funcprototype>
1580           </funcsynopsis>
1581
1582           <para>Returns the next (key, value) pair from the struct, when
1583           <parameter>$val</parameter> is a struct.
1584           <parameter>$value</parameter> is an xmlrpcval itself. See also <xref
1585           linkend="structreset" />.</para>
1586
1587           <para><programlisting language="php">
1588 // iterating over all values of a struct object
1589 $val-&gt;structreset();
1590 while (list($key, $v) = $val-&gt;structEach())
1591 {
1592   echo "Element $key of the struct is of type ".$v-&gt;kindOf();
1593 }
1594 </programlisting></para>
1595         </sect3>
1596
1597         <sect3 id="structreset" xreflabel="structreset()">
1598           <title>structReset</title>
1599
1600           <funcsynopsis>
1601             <funcprototype>
1602               <funcdef><type>void</type><function>structReset</function></funcdef>
1603
1604               <void />
1605             </funcprototype>
1606           </funcsynopsis>
1607
1608           <para>Resets the internal pointer for
1609           <function>structEach()</function> to the beginning of the struct,
1610           where <parameter>$val</parameter> is a struct.</para>
1611         </sect3>
1612
1613         <sect3 id="structmemexists" xreflabel="structmemexists()">
1614           <title>structMemExists</title>
1615
1616           <funcsynopsis>
1617             <funcprototype>
1618               <funcdef><type>bool</type><function>structMemExsists</function></funcdef>
1619
1620               <paramdef><type>string</type><parameter>$memberName</parameter></paramdef>
1621             </funcprototype>
1622           </funcsynopsis>
1623
1624           <para>Returns <constant>TRUE</constant> or
1625           <constant>FALSE</constant> depending on whether a member of the
1626           given name exists in the struct.</para>
1627         </sect3>
1628       </sect2>
1629     </sect1>
1630
1631     <sect1 id="xmlrpcmsg" xreflabel="xmlrpcmsg">
1632       <title>xmlrpcmsg</title>
1633
1634       <para>This class provides a representation for a request to an XML-RPC
1635       server. A client sends an <classname>xmlrpcmsg</classname> to a server,
1636       and receives back an <classname>xmlrpcresp</classname> (see <xref
1637       linkend="xmlrpc-client-send" />).</para>
1638
1639       <sect2>
1640         <title>Creation</title>
1641
1642         <para>The constructor takes the following forms:</para>
1643
1644         <funcsynopsis>
1645           <funcprototype>
1646             <funcdef><type>xmlrpcmsg</type>new
1647             <function>xmlrpcmsg</function></funcdef>
1648
1649             <paramdef><type>string</type><parameter>$methodName</parameter></paramdef>
1650
1651             <paramdef><type>array</type><parameter>$parameterArray</parameter><initializer>null</initializer></paramdef>
1652           </funcprototype>
1653         </funcsynopsis>
1654
1655         <para>Where <parameter>methodName</parameter> is a string indicating
1656         the name of the method you wish to invoke, and
1657         <parameter>parameterArray</parameter> is a simple php
1658         <classname>Array</classname> of <classname>xmlrpcval</classname>
1659         objects. Here's an example message to the <emphasis>US state
1660         name</emphasis> server:</para>
1661
1662         <programlisting language="php">
1663 $msg = new xmlrpcmsg("examples.getStateName", array(new xmlrpcval(23, "int")));
1664 </programlisting>
1665
1666         <para>This example requests the name of state number 23. For more
1667         information on <classname>xmlrpcval</classname> objects, see <xref
1668         linkend="xmlrpcval" />.</para>
1669
1670         <para>Note that the <parameter>parameterArray</parameter> parameter is
1671         optional and can be omitted for methods that take no input parameters
1672         or if you plan to add parameters one by one.</para>
1673       </sect2>
1674
1675       <sect2>
1676         <title>Methods</title>
1677
1678         <sect3>
1679           <title>addParam</title>
1680
1681           <funcsynopsis>
1682             <funcprototype>
1683               <funcdef><type>bool</type><function>addParam</function></funcdef>
1684
1685               <paramdef><type>xmlrpcval</type><parameter>$xmlrpcVal</parameter></paramdef>
1686             </funcprototype>
1687           </funcsynopsis>
1688
1689           <para>Adds the <classname>xmlrpcval</classname>
1690           <parameter>xmlrpcVal</parameter> to the parameter list for this
1691           method call. Returns TRUE or FALSE on error.</para>
1692         </sect3>
1693
1694         <sect3>
1695           <title>getNumParams</title>
1696
1697           <funcsynopsis>
1698             <funcprototype>
1699               <funcdef><type>int</type><function>getNumParams</function></funcdef>
1700
1701               <void />
1702             </funcprototype>
1703           </funcsynopsis>
1704
1705           <para>Returns the number of parameters attached to this
1706           message.</para>
1707         </sect3>
1708
1709         <sect3>
1710           <title>getParam</title>
1711
1712           <funcsynopsis>
1713             <funcprototype>
1714               <funcdef><type>xmlrpcval</type><function>getParam</function></funcdef>
1715
1716               <paramdef><type>int</type><parameter>$n</parameter></paramdef>
1717             </funcprototype>
1718           </funcsynopsis>
1719
1720           <para>Gets the <parameter>n</parameter>th parameter in the message
1721           (with the index zero-based). Use this method in server
1722           implementations to retrieve the values sent by the client.</para>
1723         </sect3>
1724
1725         <sect3>
1726           <title>method</title>
1727
1728           <funcsynopsis>
1729             <funcprototype>
1730               <funcdef><type>string</type><function>method</function></funcdef>
1731
1732               <void />
1733             </funcprototype>
1734
1735             <funcprototype>
1736               <funcdef><type>string</type><function>method</function></funcdef>
1737
1738               <paramdef><type>string</type><parameter>$methName</parameter></paramdef>
1739             </funcprototype>
1740           </funcsynopsis>
1741
1742           <para>Gets or sets the method contained in the XML-RPC
1743           message.</para>
1744         </sect3>
1745
1746         <sect3>
1747           <title>parseResponse</title>
1748
1749           <funcsynopsis>
1750             <funcprototype>
1751               <funcdef><type>xmlrpcresp</type><function>parseResponse</function></funcdef>
1752
1753               <paramdef><type>string</type><parameter>$xmlString</parameter></paramdef>
1754             </funcprototype>
1755           </funcsynopsis>
1756
1757           <para>Given an incoming XML-RPC server response contained in the
1758           string <parameter>$xmlString</parameter>, this method constructs an
1759           <classname>xmlrpcresp</classname> response object and returns it,
1760           setting error codes as appropriate (see <xref
1761           linkend="xmlrpc-client-send" />).</para>
1762
1763           <para>This method processes any HTTP/MIME headers it finds.</para>
1764         </sect3>
1765
1766         <sect3>
1767           <title>parseResponseFile</title>
1768
1769           <funcsynopsis>
1770             <funcprototype>
1771               <funcdef><type>xmlrpcresp</type><function>parseResponseFile</function></funcdef>
1772
1773               <paramdef><type>file handle
1774               resource</type><parameter>$fileHandle</parameter></paramdef>
1775             </funcprototype>
1776           </funcsynopsis>
1777
1778           <para>Given an incoming XML-RPC server response on the open file
1779           handle <parameter>fileHandle</parameter>, this method reads all the
1780           data it finds and passes it to
1781           <function>parseResponse.</function></para>
1782
1783           <para>This method is useful to construct responses from pre-prepared
1784           files (see files <literal>demo1.txt, demo2.txt, demo3.txt</literal>
1785           in this distribution). It processes any HTTP headers it finds, and
1786           does not close the file handle.</para>
1787         </sect3>
1788
1789         <sect3>
1790           <title>serialize</title>
1791
1792           <funcsynopsis>
1793             <funcprototype>
1794               <funcdef><type>string
1795               </type><function>serialize</function></funcdef>
1796
1797               <void />
1798             </funcprototype>
1799           </funcsynopsis>
1800
1801           <para>Returns the an XML string representing the XML-RPC
1802           message.</para>
1803         </sect3>
1804       </sect2>
1805     </sect1>
1806
1807     <sect1 id="xmlrpc-client" xreflabel="xmlrpc_client">
1808       <title>xmlrpc_client</title>
1809
1810       <para>This is the basic class used to represent a client of an XML-RPC
1811       server.</para>
1812
1813       <sect2>
1814         <title>Creation</title>
1815
1816         <para>The constructor accepts one of two possible syntaxes:</para>
1817
1818         <funcsynopsis>
1819           <funcprototype>
1820             <funcdef><type>xmlrpc_client</type>new
1821             <function>xmlrpc_client</function></funcdef>
1822
1823             <paramdef><type>string</type><parameter>$server_url</parameter></paramdef>
1824           </funcprototype>
1825
1826           <funcprototype>
1827             <funcdef><type>xmlrpc_client</type>new
1828             <function>xmlrpc_client</function></funcdef>
1829
1830             <paramdef><type>string</type><parameter>$server_path</parameter></paramdef>
1831
1832             <paramdef><type>string</type><parameter>$server_hostname</parameter></paramdef>
1833
1834             <paramdef><type>int</type><parameter>$server_port</parameter><initializer>80</initializer></paramdef>
1835
1836             <paramdef><type>string</type><parameter>$transport</parameter><initializer>'http'</initializer></paramdef>
1837           </funcprototype>
1838         </funcsynopsis>
1839
1840         <para>Here are a couple of usage examples of the first form:</para>
1841
1842         <programlisting language="php">
1843 $client = new xmlrpc_client("http://phpxmlrpc.sourceforge.net/server.php");
1844 $another_client = new xmlrpc_client("https://james:bond@secret.service.com:443/xmlrpcserver?agent=007");
1845 </programlisting>
1846
1847         <para>The second syntax does not allow to express a username and
1848         password to be used for basic HTTP authorization as in the second
1849         example above, but instead it allows to choose whether xmlrpc calls
1850         will be made using the HTTP 1.0 or 1.1 protocol.</para>
1851
1852         <para>Here's another example client set up to query Userland's XML-RPC
1853         server at <emphasis>betty.userland.com</emphasis>:</para>
1854
1855         <programlisting language="php">
1856 $client = new xmlrpc_client("/RPC2", "betty.userland.com", 80);
1857 </programlisting>
1858
1859         <para>The <parameter>server_port</parameter> parameter is optional,
1860         and if omitted will default to 80 when using HTTP and 443 when using
1861         HTTPS (see the <xref linkend="xmlrpc-client-send" /> method
1862         below).</para>
1863
1864         <para>The <parameter>transport</parameter> parameter is optional, and
1865         if omitted will default to 'http'. Allowed values are either
1866         '<symbol>http'</symbol>, '<symbol>https</symbol>' or
1867         '<symbol>http11'</symbol>. Its value can be overridden with every call
1868         to the <methodname>send</methodname> method. See the
1869         <methodname>send</methodname> method below for more details about the
1870         meaning of the different values.</para>
1871       </sect2>
1872
1873       <sect2>
1874         <title>Methods</title>
1875
1876         <para>This class supports the following methods.</para>
1877
1878         <sect3 id="xmlrpc-client-send" xreflabel="xmlrpc_client-&gt;send">
1879           <title>send</title>
1880
1881           <para>This method takes the forms:</para>
1882
1883           <funcsynopsis>
1884             <funcprototype>
1885               <funcdef><type>xmlrpcresp</type><function>send</function></funcdef>
1886
1887               <paramdef><type>xmlrpcmsg</type><parameter>$xmlrpc_message</parameter></paramdef>
1888
1889               <paramdef><type>int</type><parameter>$timeout</parameter></paramdef>
1890
1891               <paramdef><type>string</type><parameter>$transport</parameter></paramdef>
1892             </funcprototype>
1893
1894             <funcprototype>
1895               <funcdef><type>array</type><function>send</function></funcdef>
1896
1897               <paramdef><type>array</type><parameter>$xmlrpc_messages</parameter></paramdef>
1898
1899               <paramdef><type>int</type><parameter>$timeout</parameter></paramdef>
1900
1901               <paramdef><type>string</type><parameter>$transport</parameter></paramdef>
1902             </funcprototype>
1903
1904             <funcprototype>
1905               <funcdef><type>xmlrpcresp</type><function>send</function></funcdef>
1906
1907               <paramdef><type>string</type><parameter>$xml_payload</parameter></paramdef>
1908
1909               <paramdef><type>int</type><parameter>$timeout</parameter></paramdef>
1910
1911               <paramdef><type>string</type><parameter>$transport</parameter></paramdef>
1912             </funcprototype>
1913           </funcsynopsis>
1914
1915           <para>Where <parameter>xmlrpc_message</parameter> is an instance of
1916           <classname>xmlrpcmsg</classname> (see <xref linkend="xmlrpcmsg" />),
1917           and <parameter>response</parameter> is an instance of
1918           <classname>xmlrpcresp</classname> (see <xref
1919           linkend="xmlrpcresp" />).</para>
1920
1921           <para><parameter>If xmlrpc_messages</parameter> is an array of
1922           message instances, <code>responses</code> will be an array of
1923           response instances. The client will try to make use of a single
1924           <code>system.multicall</code> xml-rpc method call to forward to the
1925           server all the messages in a single HTTP round trip, unless
1926           <code>$client-&gt;no_multicall</code> has been previously set to
1927           <code>TRUE</code> (see the multicall method below), in which case
1928           many consecutive xmlrpc requests will be sent.</para>
1929
1930           <para>The third syntax allows to build by hand (or any other means)
1931           a complete xmlrpc request message, and send it to the server.
1932           <parameter>xml_payload</parameter> should be a string containing the
1933           complete xml representation of the request. It is e.g. useful when,
1934           for maximal speed of execution, the request is serialized into a
1935           string using the native php xmlrpc functions (see <ulink
1936           url="http://www.php.net/xmlrpc">the php manual on
1937           xmlrpc</ulink>).</para>
1938
1939           <para>The <parameter>timeout</parameter> is optional, and will be
1940           set to <literal>0</literal> (wait for platform-specific predefined
1941           timeout) if omitted. This timeout value is passed to
1942           <function>fsockopen()</function>. It is also used for detecting
1943           server timeouts during communication (i.e. if the server does not
1944           send anything to the client for <parameter>timeout</parameter>
1945           seconds, the connection will be closed).</para>
1946
1947           <para>The <parameter>transport</parameter> parameter is optional,
1948           and if omitted will default to the transport set using instance
1949           creator or 'http' if omitted. The only other valid values are
1950           'https', which will use an SSL HTTP connection to connect to the
1951           remote server, and 'http11'. Note that your PHP must have the "curl"
1952           extension compiled in order to use both these features. Note that
1953           when using SSL you should normally set your port number to 443,
1954           unless the SSL server you are contacting runs at any other
1955           port.</para>
1956
1957           <warning>
1958             <para>PHP 4.0.6 has a bug which prevents SSL working.</para>
1959           </warning>
1960
1961           <para>In addition to low-level errors, the XML-RPC server you were
1962           querying may return an error in the
1963           <classname>xmlrpcresp</classname> object. See <xref
1964           linkend="xmlrpcresp" /> for details of how to handle these
1965           errors.</para>
1966         </sect3>
1967
1968         <sect3 id="multicall" xreflabel="xmlrpc_client-&gt;multicall">
1969           <title>multiCall</title>
1970
1971           <para>This method takes the form:</para>
1972
1973           <funcsynopsis>
1974             <funcprototype>
1975               <funcdef><type>array</type><function>multiCall</function></funcdef>
1976
1977               <paramdef><type>array</type><parameter>$messages</parameter></paramdef>
1978
1979               <paramdef><type>int</type><parameter>$timeout</parameter></paramdef>
1980
1981               <paramdef><type>string</type><parameter>$transport</parameter></paramdef>
1982
1983               <paramdef><type>bool</type><parameter>$fallback</parameter></paramdef>
1984             </funcprototype>
1985           </funcsynopsis>
1986
1987           <para>This method is used to boxcar many method calls in a single
1988           xml-rpc request. It will try first to make use of the
1989           <code>system.multicall</code> xml-rpc method call, and fall back to
1990           executing many separate requests if the server returns any
1991           error.</para>
1992
1993           <para><parameter>msgs</parameter> is an array of
1994           <classname>xmlrpcmsg</classname> objects (see <xref
1995           linkend="xmlrpcmsg" />), and <parameter>response</parameter> is an
1996           array of <classname>xmlrpcresp</classname> objects (see <xref
1997           linkend="xmlrpcresp" />).</para>
1998
1999           <para>The <parameter>timeout</parameter> and
2000           <parameter>transport</parameter> parameters are optional, and behave
2001           as in the <methodname>send</methodname> method above.</para>
2002
2003           <para>The <parameter>fallback</parameter> parameter is optional, and
2004           defaults to <constant>TRUE</constant>. When set to
2005           <constant>FALSE</constant> it will prevent the client to try using
2006           many single method calls in case of failure of the first multicall
2007           request. It should be set only when the server is known to support
2008           the multicall extension.</para>
2009         </sect3>
2010
2011         <sect3>
2012           <title>setAcceptedCompression</title>
2013
2014           <funcsynopsis>
2015             <funcprototype>
2016               <funcdef><type>void</type><function>setAcceptedCompression</function></funcdef>
2017
2018               <paramdef><type>string</type><parameter>$compressionmethod</parameter></paramdef>
2019             </funcprototype>
2020           </funcsynopsis>
2021
2022           <para>This method defines whether the client will accept compressed
2023           xml payload forming the bodies of the xmlrpc responses received from
2024           servers. Note that enabling reception of compressed responses merely
2025           adds some standard http headers to xmlrpc requests. It is up to the
2026           xmlrpc server to return compressed responses when receiving such
2027           requests. Allowed values for
2028           <parameter>compressionmethod</parameter> are: 'gzip', 'deflate',
2029           'any' or null (with any meaning either gzip or deflate).</para>
2030
2031           <para>This requires the "zlib" extension to be enabled in your php
2032           install. If it is, by default <classname>xmlrpc_client</classname>
2033           instances will enable reception of compressed content.</para>
2034         </sect3>
2035
2036         <sect3>
2037           <title>setCaCertificate</title>
2038
2039           <funcsynopsis>
2040             <funcprototype>
2041               <funcdef><type>void</type><function>setCaCertificate</function></funcdef>
2042
2043               <paramdef><type>string</type><parameter>$certificate</parameter></paramdef>
2044
2045               <paramdef><type>bool</type><parameter>$is_dir</parameter></paramdef>
2046             </funcprototype>
2047           </funcsynopsis>
2048
2049           <para>This method sets an optional certificate to be used in
2050           SSL-enabled communication to validate a remote server with (when the
2051           <parameter>server_method</parameter> is set to 'https' in the
2052           client's construction or in the send method and
2053           <methodname>SetSSLVerifypeer</methodname> has been set to
2054           <constant>TRUE</constant>).</para>
2055
2056           <para>The <parameter>certificate</parameter> parameter must be the
2057           filename of a PEM formatted certificate, or a directory containing
2058           multiple certificate files. The <parameter>is_dir</parameter>
2059           parameter defaults to <constant>FALSE</constant>, set it to
2060           <constant>TRUE</constant> to specify that
2061           <parameter>certificate</parameter> indicates a directory instead of
2062           a single file.</para>
2063
2064           <para>This requires the "curl" extension to be compiled into your
2065           installation of PHP. For more details see the man page for the
2066           <function>curl_setopt</function> function.</para>
2067         </sect3>
2068
2069         <sect3>
2070           <title>setCertificate</title>
2071
2072           <funcsynopsis>
2073             <funcprototype>
2074               <funcdef><type>void</type><function>setCertificate</function></funcdef>
2075
2076               <paramdef><type>string</type><parameter>$certificate</parameter></paramdef>
2077
2078               <paramdef><type>string</type><parameter>$passphrase</parameter></paramdef>
2079             </funcprototype>
2080           </funcsynopsis>
2081
2082           <para>This method sets the optional certificate and passphrase used
2083           in SSL-enabled communication with a remote server (when the
2084           <parameter>server_method</parameter> is set to 'https' in the
2085           client's construction or in the send method).</para>
2086
2087           <para>The <parameter>certificate</parameter> parameter must be the
2088           filename of a PEM formatted certificate. The
2089           <parameter>passphrase</parameter> parameter must contain the
2090           password required to use the certificate.</para>
2091
2092           <para>This requires the "curl" extension to be compiled into your
2093           installation of PHP. For more details see the man page for the
2094           <function>curl_setopt</function> function.</para>
2095
2096           <para>Note: to retrieve information about the client certificate on
2097           the server side, you will need to look into the environment
2098           variables which are set up by the webserver. Different webservers
2099           will typically set up different variables.</para>
2100         </sect3>
2101
2102         <sect3>
2103           <title>setCookie</title>
2104
2105           <funcsynopsis>
2106             <funcprototype>
2107               <funcdef><type>void</type><function>setCookie</function></funcdef>
2108
2109               <paramdef><type>string</type><parameter>$name</parameter></paramdef>
2110
2111               <paramdef><type>string</type><parameter>$value</parameter></paramdef>
2112
2113               <paramdef><type>string</type><parameter>$path</parameter></paramdef>
2114
2115               <paramdef><type>string</type><parameter>$domain</parameter></paramdef>
2116
2117               <paramdef><type>int</type><parameter>$port</parameter></paramdef>
2118             </funcprototype>
2119           </funcsynopsis>
2120
2121           <para>This method sets a cookie that will be sent to the xmlrpc
2122           server along with every further request (useful e.g. for keeping
2123           session info outside of the xml-rpc payload).</para>
2124
2125           <para><parameter>$value</parameter> is optional, and defaults to
2126           null.</para>
2127
2128           <para><parameter>$path, $domain and $port</parameter> are optional,
2129           and will be omitted from the cookie header if unspecified. Note that
2130           setting any of these values will turn the cookie into a 'version 1'
2131           cookie, that might not be fully supported by the server (see RFC2965
2132           for more details).</para>
2133         </sect3>
2134
2135         <sect3>
2136           <title>setCredentials</title>
2137
2138           <funcsynopsis>
2139             <funcprototype>
2140               <funcdef><type>void</type><function>setCredentials</function></funcdef>
2141
2142               <paramdef><type>string</type><parameter>$username</parameter></paramdef>
2143
2144               <paramdef><type>string</type><parameter>$password</parameter></paramdef>
2145
2146               <paramdef><type>int</type><parameter>$authtype</parameter></paramdef>
2147             </funcprototype>
2148           </funcsynopsis>
2149
2150           <para>This method sets the username and password for authorizing the
2151           client to a server. With the default (HTTP) transport, this
2152           information is used for HTTP Basic authorization. Note that username
2153           and password can also be set using the class constructor. With HTTP
2154           1.1 and HTTPS transport, NTLM and Digest authentication protocols
2155           are also supported. To enable them use the constants
2156           <constant>CURLAUTH_DIGEST</constant> and
2157           <constant>CURLAUTH_NTLM</constant> as values for the authtype
2158           parameter.</para>
2159         </sect3>
2160
2161         <sect3>
2162           <title>setCurlOptions</title>
2163
2164           <para><funcsynopsis>
2165               <funcprototype>
2166                 <funcdef><type>void</type><function>setCurlOptions</function></funcdef>
2167
2168                 <paramdef><type>array</type><parameter>$options</parameter></paramdef>
2169               </funcprototype>
2170             </funcsynopsis>This method allows to directly set any desired
2171           option to manipulate the usage of the cURL client (when in cURL
2172           mode). It can be used eg. to explicitly bind to an outgoing ip
2173           address when the server is multihomed</para>
2174         </sect3>
2175
2176         <sect3>
2177           <title>setDebug</title>
2178
2179           <funcsynopsis>
2180             <funcprototype>
2181               <funcdef><type>void</type><function>setDebug</function></funcdef>
2182
2183               <paramdef><type>int</type><parameter>$debugLvl</parameter></paramdef>
2184             </funcprototype>
2185           </funcsynopsis>
2186
2187           <para><parameter>debugLvl</parameter> is either <literal>0,
2188           1</literal> or 2 depending on whether you require the client to
2189           print debugging information to the browser. The default is not to
2190           output this information (0).</para>
2191
2192           <para>The debugging information at level 1includes the raw data
2193           returned from the XML-RPC server it was querying (including bot HTTP
2194           headers and the full XML payload), and the PHP value the client
2195           attempts to create to represent the value returned by the server. At
2196           level2, the complete payload of the xmlrpc request is also printed,
2197           before being sent t the server.</para>
2198
2199           <para>This option can be very useful when debugging servers as it
2200           allows you to see exactly what the client sends and the server
2201           returns.</para>
2202         </sect3>
2203
2204         <sect3>
2205           <title>setKey</title>
2206
2207           <funcsynopsis>
2208             <funcprototype>
2209               <funcdef><type>void</type><function>setKey</function></funcdef>
2210
2211               <paramdef><type>int</type><parameter>$key</parameter></paramdef>
2212
2213               <paramdef><type>int</type><parameter>$keypass</parameter></paramdef>
2214             </funcprototype>
2215           </funcsynopsis>
2216
2217           <para>This method sets the optional certificate key and passphrase
2218           used in SSL-enabled communication with a remote server (when the
2219           <parameter>transport</parameter> is set to 'https' in the client's
2220           construction or in the send method).</para>
2221
2222           <para>This requires the "curl" extension to be compiled into your
2223           installation of PHP. For more details see the man page for the
2224           <function>curl_setopt</function> function.</para>
2225         </sect3>
2226
2227         <sect3>
2228           <title>setProxy</title>
2229
2230           <funcsynopsis>
2231             <funcprototype>
2232               <funcdef><type>void</type><function>setProxy</function></funcdef>
2233
2234               <paramdef><type>string</type><parameter>$proxyhost</parameter></paramdef>
2235
2236               <paramdef><type>int</type><parameter>$proxyport</parameter></paramdef>
2237
2238               <paramdef><type>string</type><parameter>$proxyusername</parameter></paramdef>
2239
2240               <paramdef><type>string</type><parameter>$proxypassword</parameter></paramdef>
2241
2242               <paramdef><type>int</type><parameter>$authtype</parameter></paramdef>
2243             </funcprototype>
2244           </funcsynopsis>
2245
2246           <para>This method enables calling servers via an HTTP proxy. The
2247           <parameter>proxyusername</parameter>,<parameter>
2248           proxypassword</parameter> and <parameter>authtype</parameter>
2249           parameters are optional. <parameter>Authtype</parameter> defaults to
2250           <constant>CURLAUTH_BASIC</constant> (Basic authentication protocol);
2251           the only other valid value is the constant
2252           <constant>CURLAUTH_NTLM</constant>, and has effect only when the
2253           client uses the HTTP 1.1 protocol.</para>
2254
2255           <para>NB: CURL versions before 7.11.10 cannot use a proxy to
2256           communicate with https servers.</para>
2257         </sect3>
2258
2259         <sect3>
2260           <title>setRequestCompression</title>
2261
2262           <funcsynopsis>
2263             <funcprototype>
2264               <funcdef><type>void</type><function>setRequestCompression</function></funcdef>
2265
2266               <paramdef><type>string</type><parameter>$compressionmethod</parameter></paramdef>
2267             </funcprototype>
2268           </funcsynopsis>
2269
2270           <para>This method defines whether the xml payload forming the
2271           request body will be sent to the server in compressed format, as per
2272           the HTTP specification. This is particularly useful for large
2273           request parameters and over slow network connections. Allowed values
2274           for <parameter>compressionmethod</parameter> are: 'gzip', 'deflate',
2275           'any' or null (with any meaning either gzip or deflate). Note that
2276           there is no automatic fallback mechanism in place for errors due to
2277           servers not supporting receiving compressed request bodies, so make
2278           sure that the particular server you are querying does accept
2279           compressed requests before turning it on.</para>
2280
2281           <para>This requires the "zlib" extension to be enabled in your php
2282           install.</para>
2283         </sect3>
2284
2285         <sect3>
2286           <title>setSSLVerifyHost</title>
2287
2288           <funcsynopsis>
2289             <funcprototype>
2290               <funcdef><type>void</type><function>setSSLVerifyHost</function></funcdef>
2291
2292               <paramdef><type>int</type><parameter>$i</parameter></paramdef>
2293             </funcprototype>
2294           </funcsynopsis>
2295
2296           <para>This method defines whether connections made to XML-RPC
2297           backends via HTTPS should verify the remote host's SSL certificate's
2298           common name (CN). By default, only the existence of a CN is checked.
2299           <parameter><parameter>$i</parameter></parameter> should be an
2300           integer value; 0 to not check the CN at all, 1 to merely check for
2301           its existence, and 2 to check that the CN on the certificate matches
2302           the hostname that is being connected to.</para>
2303         </sect3>
2304
2305         <sect3>
2306           <title>setSSLVerifyPeer</title>
2307
2308           <funcsynopsis>
2309             <funcprototype>
2310               <funcdef><type>void</type><function>setSSLVerifyPeer</function></funcdef>
2311
2312               <paramdef><type>bool</type><parameter>$i</parameter></paramdef>
2313             </funcprototype>
2314           </funcsynopsis>
2315
2316           <para>This method defines whether connections made to XML-RPC
2317           backends via HTTPS should verify the remote host's SSL certificate,
2318           and cause the connection to fail if the cert verification fails.
2319           <parameter><parameter>$i</parameter></parameter> should be a boolean
2320           value. Default value: <constant>TRUE</constant>. To specify custom
2321           SSL certificates to validate the server with, use the
2322           <methodname>setCaCertificate</methodname> method.</para>
2323         </sect3>
2324
2325         <sect3>
2326           <title>setUserAgent</title>
2327
2328           <para><funcsynopsis>
2329               <funcprototype>
2330                 <funcdef><type>void</type><function>Useragent</function></funcdef>
2331
2332                 <paramdef><type>string</type><parameter>$useragent</parameter></paramdef>
2333               </funcprototype>
2334             </funcsynopsis>This method sets a custom user-agent that will be
2335           used by the client in the http headers sent with the request. The
2336           default value is built using the library name and version
2337           constants.</para>
2338         </sect3>
2339       </sect2>
2340
2341       <sect2>
2342         <title>Variables</title>
2343
2344         <para>NB: direct manipulation of these variables is only recommended
2345         for advanced users.</para>
2346
2347         <sect3>
2348           <title>no_multicall</title>
2349
2350           <para>This member variable determines whether the multicall() method
2351           will try to take advantage of the system.multicall xmlrpc method to
2352           dispatch to the server an array of requests in a single http
2353           roundtrip or simply execute many consecutive http calls. Defaults to
2354           FALSE, but it will be enabled automatically on the first failure of
2355           execution of system.multicall.</para>
2356         </sect3>
2357
2358         <sect3>
2359           <title>request_charset_encoding</title>
2360
2361           <para>This is the charset encoding that will be used for serializing
2362           request sent by the client.</para>
2363
2364           <para>If defaults to NULL, which means using US-ASCII and encoding
2365           all characters outside of the ASCII range using their xml character
2366           entity representation (this has the benefit that line end characters
2367           will not be mangled in the transfer, a CR-LF will be preserved as
2368           well as a singe LF).</para>
2369
2370           <para>Valid values are 'US-ASCII', 'UTF-8' and 'ISO-8859-1'</para>
2371         </sect3>
2372
2373         <sect3 id="return-type" xreflabel="return_type">
2374           <title>return_type</title>
2375
2376           <para>This member variable determines whether the value returned
2377           inside an xmlrpcresp object as results of calls to the send() and
2378           multicall() methods will be an xmlrpcval object, a plain php value
2379           or a raw xml string. Allowed values are 'xmlrpcvals' (the default),
2380           'phpvals' and 'xml'. To allow the user to differentiate between a
2381           correct and a faulty response, fault responses will be returned as
2382           xmlrpcresp objects in any case. Note that the 'phpvals' setting will
2383           yield faster execution times, but some of the information from the
2384           original response will be lost. It will be e.g. impossible to tell
2385           whether a particular php string value was sent by the server as an
2386           xmlrpc string or base64 value.</para>
2387
2388           <para>Example usage:</para>
2389
2390           <programlisting language="php">
2391 $client = new xmlrpc_client("phpxmlrpc.sourceforge.net/server");
2392 $client-&gt;return_type = 'phpvals';
2393 $message = new xmlrpcmsg("examples.getStateName", array(new xmlrpcval(23, "int")));
2394 $resp = $client-&gt;send($message);
2395 if ($resp-&gt;faultCode()) echo 'KO. Error: '.$resp-&gt;faultString(); else echo 'OK: got '.$resp-&gt;value();
2396 </programlisting>
2397
2398           <para>For more details about usage of the 'xml' value, see Appendix
2399           A.</para>
2400         </sect3>
2401       </sect2>
2402     </sect1>
2403
2404     <sect1 id="xmlrpcresp" xreflabel="xmlrpcresp">
2405       <title>xmlrpcresp</title>
2406
2407       <para>This class is used to contain responses to XML-RPC requests. A
2408       server method handler will construct an
2409       <classname>xmlrpcresp</classname> and pass it as a return value. This
2410       same value will be returned by the result of an invocation of the
2411       <function>send</function> method of the
2412       <classname>xmlrpc_client</classname> class.</para>
2413
2414       <sect2>
2415         <title>Creation</title>
2416
2417         <funcsynopsis>
2418           <funcprototype>
2419             <funcdef><type>xmlrpcresp</type>new
2420             <function>xmlrpcresp</function></funcdef>
2421
2422             <paramdef><type>xmlrpcval</type><parameter>$xmlrpcval</parameter></paramdef>
2423           </funcprototype>
2424
2425           <funcprototype>
2426             <funcdef><type>xmlrpcresp</type>new
2427             <function>xmlrpcresp</function></funcdef>
2428
2429             <paramdef><parameter>0</parameter></paramdef>
2430
2431             <paramdef><type>int</type><parameter>$errcode</parameter></paramdef>
2432
2433             <paramdef><type>string</type><parameter>$err_string</parameter></paramdef>
2434           </funcprototype>
2435         </funcsynopsis>
2436
2437         <para>The first syntax is used when execution has happened without
2438         difficulty: <parameter>$xmlrpcval</parameter> is an
2439         <classname>xmlrpcval</classname> value with the result of the method
2440         execution contained in it. Alternatively it can be a string containing
2441         the xml serialization of the single xml-rpc value result of method
2442         execution.</para>
2443
2444         <para>The second type of constructor is used in case of failure.
2445         <parameter>errcode</parameter> and <parameter>err_string</parameter>
2446         are used to provide indication of what has gone wrong. See <xref
2447         linkend="xmlrpc-server" /> for more information on passing error
2448         codes.</para>
2449       </sect2>
2450
2451       <sect2>
2452         <title>Methods</title>
2453
2454         <sect3>
2455           <title>faultCode</title>
2456
2457           <funcsynopsis>
2458             <funcprototype>
2459               <funcdef><type>int</type><function>faultCode</function></funcdef>
2460
2461               <void />
2462             </funcprototype>
2463           </funcsynopsis>
2464
2465           <para>Returns the integer fault code return from the XML-RPC
2466           response. A zero value indicates success, any other value indicates
2467           a failure response.</para>
2468         </sect3>
2469
2470         <sect3>
2471           <title>faultString</title>
2472
2473           <funcsynopsis>
2474             <funcprototype>
2475               <funcdef><type>string</type><function>faultString</function></funcdef>
2476
2477               <void />
2478             </funcprototype>
2479           </funcsynopsis>
2480
2481           <para>Returns the human readable explanation of the fault indicated
2482           by <function>$resp-&gt;faultCode</function>().</para>
2483         </sect3>
2484
2485         <sect3>
2486           <title>value</title>
2487
2488           <funcsynopsis>
2489             <funcprototype>
2490               <funcdef><type>xmlrpcval</type><function>value</function></funcdef>
2491
2492               <void />
2493             </funcprototype>
2494           </funcsynopsis>
2495
2496           <para>Returns an <classname>xmlrpcval</classname> object containing
2497           the return value sent by the server. If the response's
2498           <function>faultCode</function> is non-zero then the value returned
2499           by this method should not be used (it may not even be an
2500           object).</para>
2501
2502           <para>Note: if the xmlrpcresp instance in question has been created
2503           by an <classname>xmlrpc_client</classname> object whose
2504           <varname>return_type</varname> was set to 'phpvals', then a plain
2505           php value will be returned instead of an
2506           <classname>xmlrpcval</classname> object. If the
2507           <varname>return_type</varname> was set to 'xml', an xml string will
2508           be returned (see the return_type member var above for more
2509           details).</para>
2510         </sect3>
2511
2512         <sect3>
2513           <title>serialize</title>
2514
2515           <funcsynopsis>
2516             <funcprototype>
2517               <funcdef><type>string</type><function>serialize</function></funcdef>
2518
2519               <void />
2520             </funcprototype>
2521           </funcsynopsis>
2522
2523           <para>Returns an XML string representation of the response (xml
2524           prologue not included).</para>
2525         </sect3>
2526       </sect2>
2527     </sect1>
2528
2529     <sect1 id="xmlrpc-server" xreflabel="xmlrpc_server">
2530       <title>xmlrpc_server</title>
2531
2532       <para>The implementation of this class has been kept as simple to use as
2533       possible. The constructor for the server basically does all the work.
2534       Here's a minimal example:</para>
2535
2536       <programlisting language="php">
2537   function foo ($xmlrpcmsg) {
2538     ...
2539     return new xmlrpcresp($some_xmlrpc_val);
2540   }
2541
2542   class bar {
2543     function foobar($xmlrpcmsg) {
2544       ...
2545       return new xmlrpcresp($some_xmlrpc_val);
2546     }
2547   }
2548
2549   $s = new xmlrpc_server(
2550     array(
2551       "examples.myFunc1" =&gt; array("function" =&gt; "foo"),
2552       "examples.myFunc2" =&gt; array("function" =&gt; "bar::foobar"),
2553     ));
2554 </programlisting>
2555
2556       <para>This performs everything you need to do with a server. The single
2557       constructor argument is an associative array from xmlrpc method names to
2558       php function names. The incoming request is parsed and dispatched to the
2559       relevant php function, which is responsible for returning a
2560       <classname>xmlrpcresp</classname> object, that will be serialized back
2561       to the caller.</para>
2562
2563       <sect2>
2564         <title>Method handler functions</title>
2565
2566         <para>Both php functions and class methods can be registered as xmlrpc
2567         method handlers.</para>
2568
2569         <para>The synopsis of a method handler function is:</para>
2570
2571         <para><synopsis>xmlrpcresp $resp = function (xmlrpcmsg $msg)</synopsis></para>
2572
2573         <para>No text should be echoed 'to screen' by the handler function, or
2574         it will break the xml response sent back to the client. This applies
2575         also to error and warning messages that PHP prints to screen unless
2576         the appropriate parameters have been set in the php.in file. Another
2577         way to prevent echoing of errors inside the response and facilitate
2578         debugging is to use the server SetDebug method with debug level 3 (see
2579         ...). Exceptions thrown duting execution of handler functions are
2580         caught by default and a XML-RPC error reponse is generated instead.
2581         This behaviour can be finetuned by usage of the
2582         <varname>exception_handling</varname> member variable (see
2583         ...).</para>
2584
2585         <para>Note that if you implement a method with a name prefixed by
2586         <code>system.</code> the handler function will be invoked by the
2587         server with two parameters, the first being the server itself and the
2588         second being the <classname>xmlrpcmsg</classname> object.</para>
2589
2590         <para>The same php function can be registered as handler of multiple
2591         xmlrpc methods.</para>
2592
2593         <para>Here is a more detailed example of what the handler function
2594         <function>foo</function> may do:</para>
2595
2596         <programlisting language="php">
2597   function foo ($xmlrpcmsg) {
2598     global $xmlrpcerruser; // import user errcode base value
2599
2600     $meth = $xmlrpcmsg-&gt;method(); // retrieve method name
2601     $par = $xmlrpcmsg-&gt;getParam(0); // retrieve value of first parameter - assumes at least one param received
2602     $val = $par-&gt;scalarval(); // decode value of first parameter - assumes it is a scalar value
2603
2604     ...
2605
2606     if ($err) {
2607       // this is an error condition
2608       return new xmlrpcresp(0, $xmlrpcerruser+1, // user error 1
2609         "There's a problem, Captain");
2610     } else {
2611       // this is a successful value being returned
2612       return new xmlrpcresp(new xmlrpcval("All's fine!", "string"));
2613     }
2614   }
2615 </programlisting>
2616
2617         <para>See <filename>server.php</filename> in this distribution for
2618         more examples of how to do this.</para>
2619
2620         <para>Since release 2.0RC3 there is a new, even simpler way of
2621         registering php functions with the server. See section 5.7
2622         below</para>
2623       </sect2>
2624
2625       <sect2>
2626         <title>The dispatch map</title>
2627
2628         <para>The first argument to the <function>xmlrpc_server</function>
2629         constructor is an array, called the <emphasis>dispatch map</emphasis>.
2630         In this array is the information the server needs to service the
2631         XML-RPC methods you define.</para>
2632
2633         <para>The dispatch map takes the form of an associative array of
2634         associative arrays: the outer array has one entry for each method, the
2635         key being the method name. The corresponding value is another
2636         associative array, which can have the following members:</para>
2637
2638         <itemizedlist>
2639           <listitem>
2640             <para><function><literal>function</literal></function> - this
2641             entry is mandatory. It must be either a name of a function in the
2642             global scope which services the XML-RPC method, or an array
2643             containing an instance of an object and a static method name (for
2644             static class methods the 'class::method' syntax is also
2645             supported).</para>
2646           </listitem>
2647
2648           <listitem>
2649             <para><function><literal>signature</literal></function> - this
2650             entry is an array containing the possible signatures (see <xref
2651             linkend="signatures" />) for the method. If this entry is present
2652             then the server will check that the correct number and type of
2653             parameters have been sent for this method before dispatching
2654             it.</para>
2655           </listitem>
2656
2657           <listitem>
2658             <para><function><literal>docstring</literal></function> - this
2659             entry is a string containing documentation for the method. The
2660             documentation may contain HTML markup.</para>
2661           </listitem>
2662
2663           <listitem>
2664             <para><literal>signature_docs</literal> - this entry can be used
2665             to provide documentation for the single parameters. It must match
2666             in structure the 'signature' member. By default, only the
2667             <classname>documenting_xmlrpc_server</classname> class in the
2668             extras package will take advantage of this, since the
2669             "system.methodHelp" protocol does not support documenting method
2670             parameters individually.</para>
2671           </listitem>
2672
2673           <listitem>
2674             <para><literal>parameters_type</literal> - this entry can be used
2675             when the server is working in 'xmlrpcvals' mode (see ...) to
2676             define one or more entries in the dispatch map as being functions
2677             that follow the 'phpvals' calling convention. The only useful
2678             value is currently the string <literal>phpvals</literal>.</para>
2679           </listitem>
2680         </itemizedlist>
2681
2682         <para>Look at the <filename>server.php</filename> example in the
2683         distribution to see what a dispatch map looks like.</para>
2684       </sect2>
2685
2686       <sect2 id="signatures" xreflabel="Signatures">
2687         <title>Method signatures</title>
2688
2689         <para>A signature is a description of a method's return type and its
2690         parameter types. A method may have more than one signature.</para>
2691
2692         <para>Within a server's dispatch map, each method has an array of
2693         possible signatures. Each signature is an array of types. The first
2694         entry is the return type. For instance, the method <programlisting
2695         language="php">string examples.getStateName(int)
2696 </programlisting> has the signature <programlisting language="php">array($xmlrpcString, $xmlrpcInt)
2697 </programlisting> and, assuming that it is the only possible signature for the
2698         method, it might be used like this in server creation: <programlisting
2699         language="php">
2700 $findstate_sig = array(array($xmlrpcString, $xmlrpcInt));
2701
2702 $findstate_doc = 'When passed an integer between 1 and 51 returns the
2703 name of a US state, where the integer is the index of that state name
2704 in an alphabetic order.';
2705
2706 $s = new xmlrpc_server( array(
2707   "examples.getStateName" =&gt; array(
2708     "function" =&gt; "findstate",
2709     "signature" =&gt; $findstate_sig,
2710     "docstring" =&gt; $findstate_doc
2711   )));
2712 </programlisting></para>
2713
2714         <para>Note that method signatures do not allow to check nested
2715         parameters, e.g. the number, names and types of the members of a
2716         struct param cannot be validated.</para>
2717
2718         <para>If a method that you want to expose has a definite number of
2719         parameters, but each of those parameters could reasonably be of
2720         multiple types, the array of acceptable signatures will easily grow
2721         into a combinatorial explosion. To avoid such a situation, the lib
2722         defines the global var <varname>$xmlrpcValue</varname>, which can be
2723         used in method signatures as a placeholder for 'any xmlrpc
2724         type':</para>
2725
2726         <para><programlisting language="php">
2727 $echoback_sig = array(array($xmlrpcValue, $xmlrpcValue));
2728
2729 $findstate_doc = 'Echoes back to the client the received value, regardless of its type';
2730
2731 $s = new xmlrpc_server( array(
2732   "echoBack" =&gt; array(
2733     "function" =&gt; "echoback",
2734     "signature" =&gt; $echoback_sig, // this sig guarantees that the method handler will be called with one and only one parameter
2735     "docstring" =&gt; $echoback_doc
2736   )));
2737 </programlisting></para>
2738
2739         <para>Methods <methodname>system.listMethods</methodname>,
2740         <methodname>system.methodHelp</methodname>,
2741         <methodname>system.methodSignature</methodname> and
2742         <methodname>system.multicall</methodname> are already defined by the
2743         server, and should not be reimplemented (see Reserved Methods
2744         below).</para>
2745       </sect2>
2746
2747       <sect2>
2748         <title>Delaying the server response</title>
2749
2750         <para>You may want to construct the server, but for some reason not
2751         fulfill the request immediately (security verification, for instance).
2752         If you omit to pass to the constructor the dispatch map or pass it a
2753         second argument of <literal>0</literal> this will have the desired
2754         effect. You can then use the <function>service()</function> method of
2755         the server class to service the request. For example:</para>
2756
2757         <programlisting language="php">
2758 $s = new xmlrpc_server($myDispMap, 0); // second parameter = 0 prevents automatic servicing of request
2759
2760 // ... some code that does other stuff here
2761
2762 $s-&gt;service();
2763 </programlisting>
2764
2765         <para>Note that the <methodname>service</methodname> method will print
2766         the complete result payload to screen and send appropriate HTTP
2767         headers back to the client, but also return the response object. This
2768         permits further manipulation of the response, possibly in combination
2769         with output buffering.</para>
2770
2771         <para>To prevent the server from sending HTTP headers back to the
2772         client, you can pass a second parameter with a value of
2773         <literal>TRUE</literal> to the <methodname>service</methodname>
2774         method. In this case, the response payload will be returned instead of
2775         the response object.</para>
2776
2777         <para>Xmlrpc requests retrieved by other means than HTTP POST bodies
2778         can also be processed. For example:</para>
2779
2780         <programlisting language="php">
2781 $s = new xmlrpc_server(); // not passing a dispatch map prevents automatic servicing of request
2782
2783 // ... some code that does other stuff here, including setting dispatch map into server object
2784
2785 $resp = $s-&gt;service($xmlrpc_request_body, true); // parse a variable instead of POST body, retrieve response payload
2786
2787 // ... some code that does other stuff with xml response $resp here
2788 </programlisting>
2789       </sect2>
2790
2791       <sect2>
2792         <title>Modifying the server behaviour</title>
2793
2794         <para>A couple of methods / class variables are available to modify
2795         the behaviour of the server. The only way to take advantage of their
2796         existence is by usage of a delayed server response (see above)</para>
2797
2798         <sect3>
2799           <title>setDebug()</title>
2800
2801           <para>This function controls weather the server is going to echo
2802           debugging messages back to the client as comments in response body.
2803           Valid values: 0,1,2,3, with 1 being the default. At level 0, no
2804           debug info is returned to the client. At level 2, the complete
2805           client request is added to the response, as part of the xml
2806           comments. At level 3, a new PHP error handler is set when executing
2807           user functions exposed as server methods, and all non-fatal errors
2808           are trapped and added as comments into the response.</para>
2809         </sect3>
2810
2811         <sect3>
2812           <title>allow_system_funcs</title>
2813
2814           <para>Default_value: TRUE. When set to FALSE, disables support for
2815           <methodname>System.xxx</methodname> functions in the server. It
2816           might be useful e.g. if you do not wish the server to respond to
2817           requests to <methodname>System.ListMethods</methodname>.</para>
2818         </sect3>
2819
2820         <sect3>
2821           <title>compress_response</title>
2822
2823           <para>When set to TRUE, enables the server to take advantage of HTTP
2824           compression, otherwise disables it. Responses will be transparently
2825           compressed, but only when an xmlrpc-client declares its support for
2826           compression in the HTTP headers of the request.</para>
2827
2828           <para>Note that the ZLIB php extension must be installed for this to
2829           work. If it is, <varname>compress_response</varname> will default to
2830           TRUE.</para>
2831         </sect3>
2832
2833         <sect3>
2834           <title>exception_handling</title>
2835
2836           <para>This variable controls the behaviour of the server when an
2837           exception is thrown by a method handler php function. Valid values:
2838           0,1,2, with 0 being the default. At level 0, the server catches the
2839           exception and return an 'internal error' xmlrpc response; at 1 it
2840           catches the exceptions and return an xmlrpc response with the error
2841           code and error message corresponding to the exception that was
2842           thron; at 2 = the exception is floated to the upper layers in the
2843           code</para>
2844         </sect3>
2845
2846         <sect3>
2847           <title>response_charset_encoding</title>
2848
2849           <para>Charset encoding to be used for response (only affects string
2850           values).</para>
2851
2852           <para>If it can, the server will convert the generated response from
2853           internal_encoding to the intended one.</para>
2854
2855           <para>Valid values are: a supported xml encoding (only UTF-8 and
2856           ISO-8859-1 at present, unless mbstring is enabled), null (leave
2857           charset unspecified in response and convert output stream to
2858           US_ASCII), 'default' (use xmlrpc library default as specified in
2859           xmlrpc.inc, convert output stream if needed), or 'auto' (use
2860           client-specified charset encoding or same as request if request
2861           headers do not specify it (unless request is US-ASCII: then use
2862           library default anyway).</para>
2863         </sect3>
2864       </sect2>
2865
2866       <sect2>
2867         <title>Fault reporting</title>
2868
2869         <para>Fault codes for your servers should start at the value indicated
2870         by the global <literal>$xmlrpcerruser</literal> + 1.</para>
2871
2872         <para>Standard errors returned by the server include:</para>
2873
2874         <variablelist>
2875           <varlistentry>
2876             <term><literal>1</literal> <phrase>Unknown method</phrase></term>
2877
2878             <listitem>
2879               <para>Returned if the server was asked to dispatch a method it
2880               didn't know about</para>
2881             </listitem>
2882           </varlistentry>
2883
2884           <varlistentry>
2885             <term><literal>2</literal> <phrase>Invalid return
2886             payload</phrase></term>
2887
2888             <listitem>
2889               <para>This error is actually generated by the client, not
2890               server, code, but signifies that a server returned something it
2891               couldn't understand. A more detailed error report is sometimes
2892               added onto the end of the phrase above.</para>
2893             </listitem>
2894           </varlistentry>
2895
2896           <varlistentry>
2897             <term><literal>3</literal> <phrase>Incorrect
2898             parameters</phrase></term>
2899
2900             <listitem>
2901               <para>This error is generated when the server has signature(s)
2902               defined for a method, and the parameters passed by the client do
2903               not match any of signatures.</para>
2904             </listitem>
2905           </varlistentry>
2906
2907           <varlistentry>
2908             <term><literal>4</literal> <phrase>Can't introspect: method
2909             unknown</phrase></term>
2910
2911             <listitem>
2912               <para>This error is generated by the builtin
2913               <function>system.*</function> methods when any kind of
2914               introspection is attempted on a method undefined by the
2915               server.</para>
2916             </listitem>
2917           </varlistentry>
2918
2919           <varlistentry>
2920             <term><literal>5</literal> <phrase>Didn't receive 200 OK from
2921             remote server</phrase></term>
2922
2923             <listitem>
2924               <para>This error is generated by the client when a remote server
2925               doesn't return HTTP/1.1 200 OK in response to a request. A more
2926               detailed error report is added onto the end of the phrase
2927               above.</para>
2928             </listitem>
2929           </varlistentry>
2930
2931           <varlistentry>
2932             <term><literal>6</literal> <phrase>No data received from
2933             server</phrase></term>
2934
2935             <listitem>
2936               <para>This error is generated by the client when a remote server
2937               returns HTTP/1.1 200 OK in response to a request, but no
2938               response body follows the HTTP headers.</para>
2939             </listitem>
2940           </varlistentry>
2941
2942           <varlistentry>
2943             <term><literal>7</literal> <phrase>No SSL support compiled
2944             in</phrase></term>
2945
2946             <listitem>
2947               <para>This error is generated by the client when trying to send
2948               a request with HTTPS and the CURL extension is not available to
2949               PHP.</para>
2950             </listitem>
2951           </varlistentry>
2952
2953           <varlistentry>
2954             <term><literal>8</literal> <phrase>CURL error</phrase></term>
2955
2956             <listitem>
2957               <para>This error is generated by the client when trying to send
2958               a request with HTTPS and the HTTPS communication fails.</para>
2959             </listitem>
2960           </varlistentry>
2961
2962           <varlistentry>
2963             <term><literal>9-14</literal> <phrase>multicall
2964             errors</phrase></term>
2965
2966             <listitem>
2967               <para>These errors are generated by the server when something
2968               fails inside a system.multicall request.</para>
2969             </listitem>
2970           </varlistentry>
2971
2972           <varlistentry>
2973             <term><literal>100-</literal> <phrase>XML parse
2974             errors</phrase></term>
2975
2976             <listitem>
2977               <para>Returns 100 plus the XML parser error code for the fault
2978               that occurred. The <function>faultString</function> returned
2979               explains where the parse error was in the incoming XML
2980               stream.</para>
2981             </listitem>
2982           </varlistentry>
2983         </variablelist>
2984       </sect2>
2985
2986       <sect2>
2987         <title>'New style' servers</title>
2988
2989         <para>In the same spirit of simplification that inspired the
2990         <varname>xmlrpc_client::return_type</varname> class variable, a new
2991         class variable has been added to the server class:
2992         <varname>functions_parameters_type</varname>. When set to 'phpvals',
2993         the functions registered in the server dispatch map will be called
2994         with plain php values as parameters, instead of a single xmlrpcmsg
2995         instance parameter. The return value of those functions is expected to
2996         be a plain php value, too. An example is worth a thousand
2997         words:<programlisting language="php">
2998   function foo($usr_id, $out_lang='en') {
2999     global $xmlrpcerruser;
3000
3001     ...
3002
3003     if ($someErrorCondition)
3004       return new xmlrpcresp(0, $xmlrpcerruser+1, 'DOH!');
3005     else
3006       return array(
3007         'name' =&gt; 'Joe',
3008         'age' =&gt; 27,
3009         'picture' =&gt; new xmlrpcval(file_get_contents($picOfTheGuy), 'base64')
3010       );
3011   }
3012
3013   $s = new xmlrpc_server(
3014     array(
3015       "examples.myFunc" =&gt; array(
3016         "function" =&gt; "bar::foobar",
3017         "signature" =&gt; array(
3018           array($xmlrpcString, $xmlrpcInt),
3019           array($xmlrpcString, $xmlrpcInt, $xmlrpcString)
3020         )
3021       )
3022     ), false);
3023   $s-&gt;functions_parameters_type = 'phpvals';
3024   $s-&gt;service();
3025 </programlisting>There are a few things to keep in mind when using this
3026         simplified syntax:</para>
3027
3028         <para>to return an xmlrpc error, the method handler function must
3029         return an instance of <classname>xmlrpcresp</classname>. The only
3030         other way for the server to know when an error response should be
3031         served to the client is to throw an exception and set the server's
3032         <varname>exception_handling</varname> memeber var to 1;</para>
3033
3034         <para>to return a base64 value, the method handler function must
3035         encode it on its own, creating an instance of an xmlrpcval
3036         object;</para>
3037
3038         <para>the method handler function cannot determine the name of the
3039         xmlrpc method it is serving, unlike standard handler functions that
3040         can retrieve it from the message object;</para>
3041
3042         <para>when receiving nested parameters, the method handler function
3043         has no way to distinguish a php string that was sent as base64 value
3044         from one that was sent as a string value;</para>
3045
3046         <para>this has a direct consequence on the support of
3047         system.multicall: a method whose signature contains datetime or base64
3048         values will not be available to multicall calls;</para>
3049
3050         <para>last but not least, the direct parsing of xml to php values is
3051         much faster than using xmlrpcvals, and allows the library to handle
3052         much bigger messages without allocating all available server memory or
3053         smashing PHP recursive call stack.</para>
3054       </sect2>
3055     </sect1>
3056   </chapter>
3057
3058   <chapter id="globalvars">
3059     <title>Global variables</title>
3060
3061     <para>Many global variables are defined in the xmlrpc.inc file. Some of
3062     those are meant to be used as constants (and modifying their value might
3063     cause unpredictable behaviour), while some others can be modified in your
3064     php scripts to alter the behaviour of the xml-rpc client and
3065     server.</para>
3066
3067     <sect1>
3068       <title>"Constant" variables</title>
3069
3070       <sect2>
3071         <title>$xmlrpcerruser</title>
3072
3073         <para><fieldsynopsis>
3074             <varname>$xmlrpcerruser</varname>
3075
3076             <initializer>800</initializer>
3077           </fieldsynopsis>The minimum value for errors reported by user
3078         implemented XML-RPC servers. Error numbers lower than that are
3079         reserved for library usage.</para>
3080       </sect2>
3081
3082       <sect2>
3083         <title>$xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble,
3084         $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray,
3085         $xmlrpcStruct, $xmlrpcValue, $xmlrpcNull</title>
3086
3087         <para>For convenience the strings representing the XML-RPC types have
3088         been encoded as global variables:<programlisting language="php">
3089 $xmlrpcI4="i4";
3090 $xmlrpcInt="int";
3091 $xmlrpcBoolean="boolean";
3092 $xmlrpcDouble="double";
3093 $xmlrpcString="string";
3094 $xmlrpcDateTime="dateTime.iso8601";
3095 $xmlrpcBase64="base64";
3096 $xmlrpcArray="array";
3097 $xmlrpcStruct="struct";
3098 $xmlrpcValue="undefined";
3099 $xmlrpcNull="null";
3100 </programlisting></para>
3101       </sect2>
3102
3103       <sect2>
3104         <title>$xmlrpcTypes, $xmlrpc_valid_parents, $xmlrpcerr, $xmlrpcstr,
3105         $xmlrpcerrxml, $xmlrpc_backslash, $_xh, $xml_iso88591_Entities,
3106         $xmlEntities, $xmlrpcs_capabilities</title>
3107
3108         <para>Reserved for internal usage.</para>
3109       </sect2>
3110     </sect1>
3111
3112     <sect1>
3113       <title>Variables whose value can be modified</title>
3114
3115       <sect2 id="xmlrpc-defencoding" xreflabel="xmlrpc_defencoding">
3116         <title xreflabel="">xmlrpc_defencoding</title>
3117
3118         <fieldsynopsis>
3119           <varname>$xmlrpc_defencoding</varname>
3120
3121           <initializer>"UTF8"</initializer>
3122         </fieldsynopsis>
3123
3124         <para>This variable defines the character set encoding that will be
3125         used by the xml-rpc client and server to decode the received messages,
3126         when a specific charset declaration is not found (in the messages sent
3127         non-ascii chars are always encoded using character references, so that
3128         the produced xml is valid regardless of the charset encoding
3129         assumed).</para>
3130
3131         <para>Allowed values: <literal>"UTF8"</literal>,
3132         <literal>"ISO-8859-1"</literal>, <literal>"ASCII".</literal></para>
3133
3134         <para>Note that the appropriate RFC actually mandates that XML
3135         received over HTTP without indication of charset encoding be treated
3136         as US-ASCII, but many servers and clients 'in the wild' violate the
3137         standard, and assume the default encoding is UTF-8.</para>
3138       </sect2>
3139
3140       <sect2>
3141         <title>xmlrpc_internalencoding</title>
3142
3143         <para><fieldsynopsis>
3144             <varname>$xmlrpc_internalencoding</varname>
3145
3146             <initializer>"ISO-8859-1"</initializer>
3147           </fieldsynopsis>This variable defines the character set encoding
3148         that the library uses to transparently encode into valid XML the
3149         xml-rpc values created by the user and to re-encode the received
3150         xml-rpc values when it passes them to the PHP application. It only
3151         affects xml-rpc values of string type. It is a separate value from
3152         xmlrpc_defencoding, allowing e.g. to send/receive xml messages encoded
3153         on-the-wire in US-ASCII and process them as UTF-8. It defaults to the
3154         character set used internally by PHP (unless you are running an
3155         MBString-enabled installation), so you should change it only in
3156         special situations, if e.g. the string values exchanged in the xml-rpc
3157         messages are directly inserted into / fetched from a database
3158         configured to return UTF8 encoded strings to PHP. Example
3159         usage:</para>
3160
3161         <para><programlisting language="php">
3162 &lt;?php
3163
3164 include('xmlrpc.inc');
3165 $xmlrpc_internalencoding = 'UTF-8'; // this has to be set after the inclusion above
3166 $v = new xmlrpcval('κόÏ\83με'); // This xmlrpc value will be correctly serialized as the greek word 'kosme'
3167 </programlisting></para>
3168       </sect2>
3169
3170       <sect2>
3171         <title>xmlrpcName</title>
3172
3173         <para><fieldsynopsis>
3174             <varname>$xmlrpcName</varname>
3175
3176             <initializer>"XML-RPC for PHP"</initializer>
3177           </fieldsynopsis>The string representation of the name of the XML-RPC
3178         for PHP library. It is used by the client for building the User-Agent
3179         HTTP header that is sent with every request to the server. You can
3180         change its value if you need to customize the User-Agent
3181         string.</para>
3182       </sect2>
3183
3184       <sect2>
3185         <title>xmlrpcVersion</title>
3186
3187         <para><fieldsynopsis>
3188             <varname>$xmlrpcVersion</varname>
3189
3190             <initializer>"2.2"</initializer>
3191           </fieldsynopsis>The string representation of the version number of
3192         the XML-RPC for PHP library in use. It is used by the client for
3193         building the User-Agent HTTP header that is sent with every request to
3194         the server. You can change its value if you need to customize the
3195         User-Agent string.</para>
3196       </sect2>
3197
3198       <sect2>
3199         <title>xmlrpc_null_extension</title>
3200
3201         <para>When set to <constant>TRUE</constant>, the lib will enable
3202         support for the &lt;NIL/&gt; (and &lt;EX:NIL/&gt;) xmlrpc value, as
3203         per the extension to the standard proposed here. This means that
3204         &lt;NIL/&gt; and &lt;EX:NIL/&gt; tags received will be parsed as valid
3205         xmlrpc, and the corresponding xmlrpcvals will return "null" for
3206         <methodname>scalarTyp()</methodname>.</para>
3207       </sect2>
3208
3209       <sect2>
3210         <title>xmlrpc_null_apache_encoding</title>
3211
3212         <para>When set to <literal>TRUE</literal>, php NULL values encoded
3213         into <classname>xmlrpcval</classname> objects get serialized using the
3214         <literal>&lt;EX:NIL/&gt;</literal> tag instead of
3215         <literal>&lt;NIL/&gt;</literal>. Please note that both forms are
3216         always accepted as input regardless of the value of this
3217         variable.</para>
3218       </sect2>
3219     </sect1>
3220   </chapter>
3221
3222   <chapter id="helpers">
3223     <title>Helper functions</title>
3224
3225     <para>XML-RPC for PHP contains some helper functions which you can use to
3226     make processing of XML-RPC requests easier.</para>
3227
3228     <sect1>
3229       <title>Date functions</title>
3230
3231       <para>The XML-RPC specification has this to say on dates:</para>
3232
3233       <blockquote>
3234         <para id="wrap_xmlrpc_method">Don't assume a timezone. It should be
3235         specified by the server in its documentation what assumptions it makes
3236         about timezones.</para>
3237       </blockquote>
3238
3239       <para>Unfortunately, this means that date processing isn't
3240       straightforward. Although XML-RPC uses ISO 8601 format dates, it doesn't
3241       use the timezone specifier.</para>
3242
3243       <para>We strongly recommend that in every case where you pass dates in
3244       XML-RPC calls, you use UTC (GMT) as your timezone. Most computer
3245       languages include routines for handling GMT times natively, and you
3246       won't have to translate between timezones.</para>
3247
3248       <para>For more information about dates, see <ulink
3249       url="http://www.uic.edu/year2000/datefmt.html">ISO 8601: The Right
3250       Format for Dates</ulink>, which has a handy link to a PDF of the ISO
3251       8601 specification. Note that XML-RPC uses exactly one of the available
3252       representations: CCYYMMDDTHH:MM:SS.</para>
3253
3254       <sect2 id="iso8601encode" xreflabel="iso8601_encode()">
3255         <title>iso8601_encode</title>
3256
3257         <funcsynopsis>
3258           <funcprototype>
3259             <funcdef><type>string</type><function>iso8601_encode</function></funcdef>
3260
3261             <paramdef><type>string</type><parameter>$time_t</parameter></paramdef>
3262
3263             <paramdef
3264             choice="opt"><type>int</type><parameter>$utc</parameter><initializer>0</initializer></paramdef>
3265           </funcprototype>
3266         </funcsynopsis>
3267
3268         <para>Returns an ISO 8601 formatted date generated from the UNIX
3269         timestamp <parameter>$time_t</parameter>, as returned by the PHP
3270         function <function>time()</function>.</para>
3271
3272         <para>The argument <parameter>$utc</parameter> can be omitted, in
3273         which case it defaults to <literal>0</literal>. If it is set to
3274         <literal>1</literal>, then the function corrects the time passed in
3275         for UTC. Example: if you're in the GMT-6:00 timezone and set
3276         <parameter>$utc</parameter>, you will receive a date representation
3277         six hours ahead of your local time.</para>
3278
3279         <para>The included demo program <filename>vardemo.php</filename>
3280         includes a demonstration of this function.</para>
3281       </sect2>
3282
3283       <sect2 id="iso8601decode" xreflabel="iso8601_decode()">
3284         <title>iso8601_decode</title>
3285
3286         <funcsynopsis>
3287           <funcprototype>
3288             <funcdef><type>int</type><function>iso8601_decode</function></funcdef>
3289
3290             <paramdef><type>string</type><parameter>$isoString</parameter></paramdef>
3291
3292             <paramdef><type>int</type><parameter>$utc</parameter><initializer>0</initializer></paramdef>
3293           </funcprototype>
3294         </funcsynopsis>
3295
3296         <para>Returns a UNIX timestamp from an ISO 8601 encoded time and date
3297         string passed in. If <parameter>$utc</parameter> is
3298         <literal>1</literal> then <parameter>$isoString</parameter> is assumed
3299         to be in the UTC timezone, and thus the result is also UTC: otherwise,
3300         the timezone is assumed to be your local timezone and you receive a
3301         local timestamp.</para>
3302       </sect2>
3303     </sect1>
3304
3305     <sect1 id="arrayuse">
3306       <title>Easy use with nested PHP values</title>
3307
3308       <para>Dan Libby was kind enough to contribute two helper functions that
3309       make it easier to translate to and from PHP values. This makes it easier
3310       to deal with complex structures. At the moment support is limited to
3311       <type>int</type>, <type>double</type>, <type>string</type>,
3312       <type>array</type>, <type>datetime</type> and <type>struct</type>
3313       datatypes; note also that all PHP arrays are encoded as structs, except
3314       arrays whose keys are integer numbers starting with 0 and incremented by
3315       1.</para>
3316
3317       <para>These functions reside in <filename>xmlrpc.inc</filename>.</para>
3318
3319       <sect2 id="phpxmlrpcdecode">
3320         <title>php_xmlrpc_decode</title>
3321
3322         <funcsynopsis>
3323           <funcprototype>
3324             <funcdef><type>mixed</type><function>php_xmlrpc_decode</function></funcdef>
3325
3326             <paramdef><type>xmlrpcval</type><parameter>$xmlrpc_val</parameter></paramdef>
3327
3328             <paramdef><type>array</type><parameter>$options</parameter></paramdef>
3329           </funcprototype>
3330
3331           <funcprototype>
3332             <funcdef><type>array</type><function>php_xmlrpc_decode</function></funcdef>
3333
3334             <paramdef><type>xmlrpcmsg</type><parameter>$xmlrpcmsg_val</parameter></paramdef>
3335
3336             <paramdef><type>string</type><parameter>$options</parameter></paramdef>
3337           </funcprototype>
3338         </funcsynopsis>
3339
3340         <para>Returns a native PHP value corresponding to the values found in
3341         the <type>xmlrpcval</type> <parameter>$xmlrpc_val</parameter>,
3342         translated into PHP types. Base-64 and datetime values are
3343         automatically decoded to strings.</para>
3344
3345         <para>In the second form, returns an array containing the parameters
3346         of the given
3347         <parameter><classname>xmlrpcmsg</classname>_val</parameter>, decoded
3348         to php types.</para>
3349
3350         <para>The <parameter>options</parameter> parameter is optional. If
3351         specified, it must consist of an array of options to be enabled in the
3352         decoding process. At the moment the only valid option are
3353         <symbol>decode_php_objs</symbol> and
3354         <literal>dates_as_objects</literal>. When the first is set, php
3355         objects that have been converted to xml-rpc structs using the
3356         <function>php_xmlrpc_encode</function> function and a corresponding
3357         encoding option will be converted back into object values instead of
3358         arrays (provided that the class definition is available at
3359         reconstruction time). When the second is set, XML-RPC datetime values
3360         will be converted into native <classname>dateTime</classname> objects
3361         instead of strings.</para>
3362
3363         <para><emphasis><emphasis>WARNING</emphasis>:</emphasis> please take
3364         extreme care before enabling the <symbol>decode_php_objs</symbol>
3365         option: when php objects are rebuilt from the received xml, their
3366         constructor function will be silently invoked. This means that you are
3367         allowing the remote end to trigger execution of uncontrolled PHP code
3368         on your server, opening the door to code injection exploits. Only
3369         enable this option when you have complete trust of the remote
3370         server/client.</para>
3371
3372         <para>Example:<programlisting language="php">
3373 // wrapper to expose an existing php function as xmlrpc method handler
3374 function foo_wrapper($m)
3375 {
3376   $params = php_xmlrpc_decode($m);
3377   $retval = call_user_func_array('foo', $params);
3378   return new xmlrpcresp(new xmlrpcval($retval)); // foo return value will be serialized as string
3379 }
3380
3381 $s = new xmlrpc_server(array(
3382    "examples.myFunc1" =&gt; array(
3383      "function" =&gt; "foo_wrapper",
3384      "signatures" =&gt; ...
3385   )));
3386 </programlisting></para>
3387       </sect2>
3388
3389       <sect2 id="phpxmlrpcencode">
3390         <title>php_xmlrpc_encode</title>
3391
3392         <funcsynopsis>
3393           <funcprototype>
3394             <funcdef><type>xmlrpcval</type><function>php_xmlrpc_encode</function></funcdef>
3395
3396             <paramdef><type>mixed</type><parameter>$phpval</parameter></paramdef>
3397
3398             <paramdef><type>array</type><parameter>$options</parameter></paramdef>
3399           </funcprototype>
3400         </funcsynopsis>
3401
3402         <para>Returns an <type>xmlrpcval</type> object populated with the PHP
3403         values in <parameter>$phpval</parameter>. Works recursively on arrays
3404         and objects, encoding numerically indexed php arrays into array-type
3405         xmlrpcval objects and non numerically indexed php arrays into
3406         struct-type xmlrpcval objects. Php objects are encoded into
3407         struct-type xmlrpcvals, excepted for php values that are already
3408         instances of the xmlrpcval class or descendants thereof, which will
3409         not be further encoded. Note that there's no support for encoding php
3410         values into base-64 values. Encoding of date-times is optionally
3411         carried on on php strings with the correct format.</para>
3412
3413         <para>The <parameter>options</parameter> parameter is optional. If
3414         specified, it must consist of an array of options to be enabled in the
3415         encoding process. At the moment the only valid options are
3416         <symbol>encode_php_objs</symbol>, <literal>null_extension</literal>
3417         and <symbol>auto_dates</symbol>.</para>
3418
3419         <para>The first will enable the creation of 'particular' xmlrpcval
3420         objects out of php objects, that add a "php_class" xml attribute to
3421         their serialized representation. This attribute allows the function
3422         php_xmlrpc_decode to rebuild the native php objects (provided that the
3423         same class definition exists on both sides of the communication). The
3424         second allows to encode php <literal>NULL</literal> values to the
3425         <literal>&lt;NIL/&gt;</literal> (or
3426         <literal>&lt;EX:NIL/&gt;</literal>, see ...) tag. The last encodes any
3427         string that matches the ISO8601 format into an XML-RPC
3428         datetime.</para>
3429
3430         <para>Example:<programlisting language="php">
3431 // the easy way to build a complex xml-rpc struct, showing nested base64 value and datetime values
3432 $val = php_xmlrpc_encode(array(
3433   'first struct_element: an int' =&gt; 666,
3434   'second: an array' =&gt; array ('apple', 'orange', 'banana'),
3435   'third: a base64 element' =&gt; new xmlrpcval('hello world', 'base64'),
3436   'fourth: a datetime' =&gt; '20060107T01:53:00'
3437   ), array('auto_dates'));
3438 </programlisting></para>
3439       </sect2>
3440
3441       <sect2>
3442         <title>php_xmlrpc_decode_xml</title>
3443
3444         <funcsynopsis>
3445           <funcprototype>
3446             <funcdef><type>xmlrpcval | xmlrpcresp |
3447             xmlrpcmsg</type><function>php_xmlrpc_decode_xml</function></funcdef>
3448
3449             <paramdef><type>string</type><parameter>$xml</parameter></paramdef>
3450
3451             <paramdef><type>array</type><parameter>$options</parameter></paramdef>
3452           </funcprototype>
3453         </funcsynopsis>
3454
3455         <para>Decodes the xml representation of either an xmlrpc request,
3456         response or single value, returning the corresponding php-xmlrpc
3457         object, or <literal>FALSE</literal> in case of an error.</para>
3458
3459         <para>The <parameter>options</parameter> parameter is optional. If
3460         specified, it must consist of an array of options to be enabled in the
3461         decoding process. At the moment, no option is supported.</para>
3462
3463         <para>Example:<programlisting language="php">
3464 $text = '&lt;value&gt;&lt;array&gt;&lt;data&gt;&lt;value&gt;Hello world&lt;/value&gt;&lt;/data&gt;&lt;/array&gt;&lt;/value&gt;';
3465 $val = php_xmlrpc_decode_xml($text);
3466 if ($val) echo 'Found a value of type '.$val-&gt;kindOf(); else echo 'Found invalid xml';
3467 </programlisting></para>
3468       </sect2>
3469     </sect1>
3470
3471     <sect1>
3472       <title>Automatic conversion of php functions into xmlrpc methods (and
3473       vice versa)</title>
3474
3475       <para>For the extremely lazy coder, helper functions have been added
3476       that allow to convert a php function into an xmlrpc method, and a
3477       remotely exposed xmlrpc method into a local php function - or a set of
3478       methods into a php class. Note that these comes with many caveat.</para>
3479
3480       <sect2>
3481         <title>wrap_xmlrpc_method</title>
3482
3483         <funcsynopsis>
3484           <funcprototype>
3485             <funcdef><type>string</type><function>wrap_xmlrpc_method</function></funcdef>
3486
3487             <paramdef>$client</paramdef>
3488
3489             <paramdef>$methodname</paramdef>
3490
3491             <paramdef>$extra_options</paramdef>
3492           </funcprototype>
3493
3494           <funcprototype>
3495             <funcdef><type>string</type><function>wrap_xmlrpc_method</function></funcdef>
3496
3497             <paramdef>$client</paramdef>
3498
3499             <paramdef>$methodname</paramdef>
3500
3501             <paramdef>$signum</paramdef>
3502
3503             <paramdef>$timeout</paramdef>
3504
3505             <paramdef>$protocol</paramdef>
3506
3507             <paramdef>$funcname</paramdef>
3508           </funcprototype>
3509         </funcsynopsis>
3510
3511         <para>Given an xmlrpc server and a method name, creates a php wrapper
3512         function that will call the remote method and return results using
3513         native php types for both params and results. The generated php
3514         function will return an xmlrpcresp object for failed xmlrpc
3515         calls.</para>
3516
3517         <para>The second syntax is deprecated, and is listed here only for
3518         backward compatibility.</para>
3519
3520         <para>The server must support the
3521         <methodname>system.methodSignature</methodname> xmlrpc method call for
3522         this function to work.</para>
3523
3524         <para>The <parameter>client</parameter> param must be a valid
3525         xmlrpc_client object, previously created with the address of the
3526         target xmlrpc server, and to which the preferred communication options
3527         have been set.</para>
3528
3529         <para>The optional parameters can be passed as array key,value pairs
3530         in the <parameter>extra_options</parameter> param.</para>
3531
3532         <para>The <parameter>signum</parameter> optional param has the purpose
3533         of indicating which method signature to use, if the given server
3534         method has multiple signatures (defaults to 0).</para>
3535
3536         <para>The <parameter>timeout</parameter> and
3537         <parameter>protocol</parameter> optional params are the same as in the
3538         <methodname>xmlrpc_client::send()</methodname> method.</para>
3539
3540         <para>If set, the optional <parameter>new_function_name</parameter>
3541         parameter indicates which name should be used for the generated
3542         function. In case it is not set the function name will be
3543         auto-generated.</para>
3544
3545         <para>If the <literal>return_source</literal> optional parameter is
3546         set, the function will return the php source code to build the wrapper
3547         function, instead of evaluating it (useful to save the code and use it
3548         later as stand-alone xmlrpc client).</para>
3549
3550         <para>If the <literal>encode_php_objs</literal> optional parameter is
3551         set, instances of php objects later passed as parameters to the newly
3552         created function will receive a 'special' treatment that allows the
3553         server to rebuild them as php objects instead of simple arrays. Note
3554         that this entails using a "slightly augmented" version of the xmlrpc
3555         protocol (ie. using element attributes), which might not be understood
3556         by xmlrpc servers implemented using other libraries.</para>
3557
3558         <para>If the <literal>decode_php_objs</literal> optional parameter is
3559         set, instances of php objects that have been appropriately encoded by
3560         the server using a coordinate option will be deserialized as php
3561         objects instead of simple arrays (the same class definition should be
3562         present server side and client side).</para>
3563
3564         <para><emphasis>Note that this might pose a security risk</emphasis>,
3565         since in order to rebuild the object instances their constructor
3566         method has to be invoked, and this means that the remote server can
3567         trigger execution of unforeseen php code on the client: not really a
3568         code injection, but almost. Please enable this option only when you
3569         trust the remote server.</para>
3570
3571         <para>In case of an error during generation of the wrapper function,
3572         FALSE is returned, otherwise the name (or source code) of the new
3573         function.</para>
3574
3575         <para>Known limitations: server must support
3576         <methodname>system.methodsignature</methodname> for the wanted xmlrpc
3577         method; for methods that expose multiple signatures, only one can be
3578         picked; for remote calls with nested xmlrpc params, the caller of the
3579         generated php function has to encode on its own the params passed to
3580         the php function if these are structs or arrays whose (sub)members
3581         include values of type base64.</para>
3582
3583         <para>Note: calling the generated php function 'might' be slow: a new
3584         xmlrpc client is created on every invocation and an xmlrpc-connection
3585         opened+closed. An extra 'debug' param is appended to the parameter
3586         list of the generated php function, useful for debugging
3587         purposes.</para>
3588
3589         <para>Example usage:</para>
3590
3591         <programlisting language="php">
3592 $c = new xmlrpc_client('http://phpxmlrpc.sourceforge.net/server.php');
3593
3594 $function = wrap_xmlrpc_method($client, 'examples.getStateName');
3595
3596 if (!$function)
3597   die('Cannot introspect remote method');
3598 else {
3599   $stateno = 15;
3600   $statename = $function($a);
3601   if (is_a($statename, 'xmlrpcresp')) // call failed
3602   {
3603     echo 'Call failed: '.$statename-&gt;faultCode().'. Calling again with debug on';
3604     $function($a, true);
3605   }
3606   else
3607     echo "OK, state nr. $stateno is $statename";
3608 }
3609 </programlisting>
3610       </sect2>
3611
3612       <sect2 id="wrap_php_function">
3613         <title>wrap_php_function</title>
3614
3615         <funcsynopsis>
3616           <funcprototype>
3617             <funcdef><type>array</type><function>wrap_php_function</function></funcdef>
3618
3619             <paramdef><type>string</type><parameter>$funcname</parameter></paramdef>
3620
3621             <paramdef><type>string</type><parameter>$wrapper_function_name</parameter></paramdef>
3622
3623             <paramdef><type>array</type><parameter>$extra_options</parameter></paramdef>
3624           </funcprototype>
3625         </funcsynopsis>
3626
3627         <para>Given a user-defined PHP function, create a PHP 'wrapper'
3628         function that can be exposed as xmlrpc method from an xmlrpc_server
3629         object and called from remote clients, and return the appropriate
3630         definition to be added to a server's dispatch map.</para>
3631
3632         <para>The optional <parameter>$wrapper_function_name</parameter>
3633         specifies the name that will be used for the auto-generated
3634         function.</para>
3635
3636         <para>Since php is a typeless language, to infer types of input and
3637         output parameters, it relies on parsing the javadoc-style comment
3638         block associated with the given function. Usage of xmlrpc native types
3639         (such as datetime.dateTime.iso8601 and base64) in the docblock @param
3640         tag is also allowed, if you need the php function to receive/send data
3641         in that particular format (note that base64 encoding/decoding is
3642         transparently carried out by the lib, while datetime vals are passed
3643         around as strings).</para>
3644
3645         <para>Known limitations: requires PHP 5.0.3 +; only works for
3646         user-defined functions, not for PHP internal functions (reflection
3647         does not support retrieving number/type of params for those); the
3648         wrapped php function will not be able to programmatically return an
3649         xmlrpc error response.</para>
3650
3651         <para>If the <literal>return_source</literal> optional parameter is
3652         set, the function will return the php source code to build the wrapper
3653         function, instead of evaluating it (useful to save the code and use it
3654         later in a stand-alone xmlrpc server). It will be in the stored in the
3655         <literal>source</literal> member of the returned array.</para>
3656
3657         <para>If the <literal>suppress_warnings</literal> optional parameter
3658         is set, any runtime warning generated while processing the
3659         user-defined php function will be catched and not be printed in the
3660         generated xml response.</para>
3661
3662         <para>If the <parameter>extra_options</parameter> array contains the
3663         <literal>encode_php_objs</literal> value, wrapped functions returning
3664         php objects will generate "special" xmlrpc responses: when the xmlrpc
3665         decoding of those responses is carried out by this same lib, using the
3666         appropriate param in php_xmlrpc_decode(), the objects will be
3667         rebuilt.</para>
3668
3669         <para>In short: php objects can be serialized, too (except for their
3670         resource members), using this function. Other libs might choke on the
3671         very same xml that will be generated in this case (i.e. it has a
3672         nonstandard attribute on struct element tags)</para>
3673
3674         <para>If the <literal>decode_php_objs</literal> optional parameter is
3675         set, instances of php objects that have been appropriately encoded by
3676         the client using a coordinate option will be deserialized and passed
3677         to the user function as php objects instead of simple arrays (the same
3678         class definition should be present server side and client
3679         side).</para>
3680
3681         <para><emphasis>Note that this might pose a security risk</emphasis>,
3682         since in order to rebuild the object instances their constructor
3683         method has to be invoked, and this means that the remote client can
3684         trigger execution of unforeseen php code on the server: not really a
3685         code injection, but almost. Please enable this option only when you
3686         trust the remote clients.</para>
3687
3688         <para>Example usage:</para>
3689
3690         <para><programlisting language="php">/**
3691 * State name from state number decoder. NB: do NOT remove this comment block.
3692 * @param integer $stateno the state number
3693 * @return string the name of the state (or error description)
3694 */
3695 function findstate($stateno)
3696 {
3697   global $stateNames;
3698   if (isset($stateNames[$stateno-1]))
3699   {
3700     return $stateNames[$stateno-1];
3701   }
3702   else
3703   {
3704     return "I don't have a state for the index '" . $stateno . "'";
3705   }
3706 }
3707
3708 // wrap php function, build xmlrpc server
3709 $methods = array();
3710 $findstate_sig = wrap_php_function('findstate');
3711 if ($findstate_sig)
3712   $methods['examples.getStateName'] = $findstate_sig;
3713 $srv = new xmlrpc_server($methods);
3714 </programlisting></para>
3715       </sect2>
3716     </sect1>
3717
3718     <sect1 id="deprecated">
3719       <title>Functions removed from the library</title>
3720
3721       <para>The following two functions have been deprecated in version 1.1 of
3722       the library, and removed in version 2, in order to avoid conflicts with
3723       the EPI xml-rpc library, which also defines two functions with the same
3724       names.</para>
3725
3726       <para>To ease the transition to the new naming scheme and avoid breaking
3727       existing implementations, the following scheme has been adopted:
3728       <itemizedlist>
3729           <listitem>
3730             <para>If EPI-XMLRPC is not active in the current PHP installation,
3731             the constant <literal>XMLRPC_EPI_ENABLED</literal> will be set to
3732             <literal>'0'</literal></para>
3733           </listitem>
3734
3735           <listitem>
3736             <para>If EPI-XMLRPC is active in the current PHP installation, the
3737             constant <literal>XMLRPC_EPI_ENABLED</literal> will be set to
3738             <literal>'1'</literal></para>
3739           </listitem>
3740         </itemizedlist></para>
3741
3742       <para>The following documentation is kept for historical
3743       reference:</para>
3744
3745       <sect2 id="xmlrpcdecode">
3746         <title>xmlrpc_decode</title>
3747
3748         <funcsynopsis>
3749           <funcprototype>
3750             <funcdef><type>mixed</type><function>xmlrpc_decode</function></funcdef>
3751
3752             <paramdef><type>xmlrpcval</type><parameter>$xmlrpc_val</parameter></paramdef>
3753           </funcprototype>
3754         </funcsynopsis>
3755
3756         <para>Alias for php_xmlrpc_decode.</para>
3757       </sect2>
3758
3759       <sect2 id="xmlrpcencode">
3760         <title>xmlrpc_encode</title>
3761
3762         <funcsynopsis>
3763           <funcprototype>
3764             <funcdef><type>xmlrpcval</type><function>xmlrpc_encode</function></funcdef>
3765
3766             <paramdef><type>mixed</type><parameter>$phpval</parameter></paramdef>
3767           </funcprototype>
3768         </funcsynopsis>
3769
3770         <para>Alias for php_xmlrpc_encode.</para>
3771       </sect2>
3772     </sect1>
3773
3774     <sect1 id="debugging">
3775       <title>Debugging aids</title>
3776
3777       <sect2>
3778         <title>xmlrpc_debugmsg</title>
3779
3780         <funcsynopsis>
3781           <funcprototype>
3782             <funcdef><type>void</type><function>xmlrpc_debugmsg</function></funcdef>
3783
3784             <paramdef><type>string</type><parameter>$debugstring</parameter></paramdef>
3785           </funcprototype>
3786         </funcsynopsis>
3787
3788         <para>Sends the contents of <parameter>$debugstring</parameter> in XML
3789         comments in the server return payload. If a PHP client has debugging
3790         turned on, the user will be able to see server debug
3791         information.</para>
3792
3793         <para>Use this function in your methods so you can pass back
3794         diagnostic information. It is only available from
3795         <filename>xmlrpcs.inc</filename>.</para>
3796       </sect2>
3797     </sect1>
3798   </chapter>
3799
3800   <chapter id="reserved" xreflabel="Reserved methods">
3801     <title>Reserved methods</title>
3802
3803     <para>In order to extend the functionality offered by XML-RPC servers
3804     without impacting on the protocol, reserved methods are supported in this
3805     release.</para>
3806
3807     <para>All methods starting with <function>system.</function> are
3808     considered reserved by the server. PHP for XML-RPC itself provides four
3809     special methods, detailed in this chapter.</para>
3810
3811     <para>Note that all server objects will automatically respond to clients
3812     querying these methods, unless the property
3813     <property>allow_system_funcs</property> has been set to
3814     <constant>false</constant> before calling the
3815     <methodname>service()</methodname> method. This might pose a security risk
3816     if the server is exposed to public access, e.g. on the internet.</para>
3817
3818     <sect1>
3819       <title>system.getCapabilities</title>
3820
3821       <para></para>
3822     </sect1>
3823
3824     <sect1>
3825       <title>system.listMethods</title>
3826
3827       <para>This method may be used to enumerate the methods implemented by
3828       the XML-RPC server.</para>
3829
3830       <para>The <function>system.listMethods</function> method requires no
3831       parameters. It returns an array of strings, each of which is the name of
3832       a method implemented by the server.</para>
3833     </sect1>
3834
3835     <sect1 id="sysmethodsig">
3836       <title>system.methodSignature</title>
3837
3838       <para>This method takes one parameter, the name of a method implemented
3839       by the XML-RPC server.</para>
3840
3841       <para>It returns an array of possible signatures for this method. A
3842       signature is an array of types. The first of these types is the return
3843       type of the method, the rest are parameters.</para>
3844
3845       <para>Multiple signatures (i.e. overloading) are permitted: this is the
3846       reason that an array of signatures are returned by this method.</para>
3847
3848       <para>Signatures themselves are restricted to the top level parameters
3849       expected by a method. For instance if a method expects one array of
3850       structs as a parameter, and it returns a string, its signature is simply
3851       "string, array". If it expects three integers, its signature is "string,
3852       int, int, int".</para>
3853
3854       <para>For parameters that can be of more than one type, the "undefined"
3855       string is supported.</para>
3856
3857       <para>If no signature is defined for the method, a not-array value is
3858       returned. Therefore this is the way to test for a non-signature, if
3859       <parameter>$resp</parameter> below is the response object from a method
3860       call to <function>system.methodSignature</function>:</para>
3861
3862       <programlisting language="php">
3863 $v = $resp-&gt;value();
3864 if ($v-&gt;kindOf() != "array") {
3865   // then the method did not have a signature defined
3866 }
3867 </programlisting>
3868
3869       <para>See the <filename>introspect.php</filename> demo included in this
3870       distribution for an example of using this method.</para>
3871     </sect1>
3872
3873     <sect1 id="sysmethhelp">
3874       <title>system.methodHelp</title>
3875
3876       <para>This method takes one parameter, the name of a method implemented
3877       by the XML-RPC server.</para>
3878
3879       <para>It returns a documentation string describing the use of that
3880       method. If no such string is available, an empty string is
3881       returned.</para>
3882
3883       <para>The documentation string may contain HTML markup.</para>
3884     </sect1>
3885
3886     <sect1>
3887       <title>system.multicall</title>
3888
3889       <para>This method takes one parameter, an array of 'request' struct
3890       types. Each request struct must contain a
3891       <parameter>methodName</parameter> member of type string and a
3892       <parameter>params</parameter> member of type array, and corresponds to
3893       the invocation of the corresponding method.</para>
3894
3895       <para>It returns a response of type array, with each value of the array
3896       being either an error struct (containing the faultCode and faultString
3897       members) or the successful response value of the corresponding single
3898       method call.</para>
3899     </sect1>
3900   </chapter>
3901
3902   <chapter id="examples" xreflabel="Examples">
3903     <title>Examples</title>
3904
3905     <para>The best examples are to be found in the sample files included with
3906     the distribution. Some are included here.</para>
3907
3908     <sect1 id="statename">
3909       <title>XML-RPC client: state name query</title>
3910
3911       <para>Code to get the corresponding state name from a number (1-50) from
3912       the demo server available on SourceForge</para>
3913
3914       <programlisting language="php">
3915   $m = new xmlrpcmsg('examples.getStateName',
3916     array(new xmlrpcval($HTTP_POST_VARS["stateno"], "int")));
3917   $c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80);
3918   $r = $c-&gt;send($m);
3919   if (!$r-&gt;faultCode()) {
3920       $v = $r-&gt;value();
3921       print "State number " . htmlentities($HTTP_POST_VARS["stateno"]) . " is " .
3922         htmlentities($v-&gt;scalarval()) . "&lt;BR&gt;";
3923       print "&lt;HR&gt;I got this value back&lt;BR&gt;&lt;PRE&gt;" .
3924         htmlentities($r-&gt;serialize()) . "&lt;/PRE&gt;&lt;HR&gt;\n";
3925   } else {
3926       print "Fault &lt;BR&gt;";
3927       print "Code: " . htmlentities($r-&gt;faultCode()) . "&lt;BR&gt;" .
3928             "Reason: '" . htmlentities($r-&gt;faultString()) . "'&lt;BR&gt;";
3929   }
3930 </programlisting>
3931     </sect1>
3932
3933     <sect1>
3934       <title>Executing a multicall call</title>
3935
3936       <para>To be documented...</para>
3937     </sect1>
3938   </chapter>
3939
3940   <chapter id="faq">
3941     <title>Frequently Asked Questions</title>
3942
3943     <sect1>
3944       <title>How to send custom XML as payload of a method call</title>
3945
3946       <para>Unfortunately, at the time the XML-RPC spec was designed, support
3947       for namespaces in XML was not as ubiquitous as it is now. As a
3948       consequence, no support was provided in the protocol for embedding XML
3949       elements from other namespaces into an xmlrpc request.</para>
3950
3951       <para>To send an XML "chunk" as payload of a method call or response,
3952       two options are available: either send the complete XML block as a
3953       string xmlrpc value, or as a base64 value. Since the '&lt;' character in
3954       string values is encoded as '&amp;lt;' in the xml payload of the method
3955       call, the XML string will not break the surrounding xmlrpc, unless
3956       characters outside of the assumed character set are used. The second
3957       method has the added benefits of working independently of the charset
3958       encoding used for the xml to be transmitted, and preserving exactly
3959       whitespace, whilst incurring in some extra message length and cpu load
3960       (for carrying out the base64 encoding/decoding).</para>
3961     </sect1>
3962
3963     <sect1>
3964       <title>Is there any limitation on the size of the requests / responses
3965       that can be successfully sent?</title>
3966
3967       <para>Yes. But I have no hard figure to give; it most likely will depend
3968       on the version of PHP in usage and its configuration.</para>
3969
3970       <para>Keep in mind that this library is not optimized for speed nor for
3971       memory usage. Better alternatives exist when there are strict
3972       requirements on throughput or resource usage, such as the php native
3973       xmlrpc extension (see the PHP manual for more information).</para>
3974
3975       <para>Keep in mind also that HTTP is probably not the best choice in
3976       such a situation, and XML is a deadly enemy. CSV formatted data over
3977       socket would be much more efficient.</para>
3978
3979       <para>If you really need to move a massive amount of data around, and
3980       you are crazy enough to do it using phpxmlrpc, your best bet is to
3981       bypass usage of the xmlrpcval objects, at least in the decoding phase,
3982       and have the server (or client) object return to the calling function
3983       directly php values (see <varname>xmlrpc_client::return_type</varname>
3984       and <varname>xmlrpc_server::functions_parameters_type</varname> for more
3985       details).</para>
3986     </sect1>
3987
3988     <sect1>
3989       <title>My server (client) returns an error whenever the client (server)
3990       returns accented characters</title>
3991
3992       <para>To be documented...</para>
3993     </sect1>
3994
3995     <sect1>
3996       <title>How to enable long-lasting method calls</title>
3997
3998       <para>To be documented...</para>
3999     </sect1>
4000
4001     <sect1>
4002       <title>My client returns "XML-RPC Fault #2: Invalid return payload:
4003       enable debugging to examine incoming payload": what should I do?</title>
4004
4005       <para>The response you are seeing is a default error response that the
4006       client object returns to the php application when the server did not
4007       respond to the call with a valid xmlrpc response.</para>
4008
4009       <para>The most likely cause is that you are not using the correct URL
4010       when creating the client object, or you do not have appropriate access
4011       rights to the web page you are requesting, or some other common http
4012       misconfiguration.</para>
4013
4014       <para>To find out what the server is really returning to your client,
4015       you have to enable the debug mode of the client, using
4016       $client-&gt;setdebug(1);</para>
4017     </sect1>
4018
4019     <sect1>
4020       <title>How can I save to a file the xml of the xmlrpc responses received
4021       from servers?</title>
4022
4023       <para>If what you need is to save the responses received from the server
4024       as xml, you have two options:</para>
4025
4026       <para>1- use the serialize() method on the response object.</para>
4027
4028       <programlisting language="php">
4029 $resp = $client-&gt;send($msg);
4030 if (!$resp-&gt;faultCode())
4031   $data_to_be_saved = $resp-&gt;serialize();
4032 </programlisting>
4033
4034       <para>Note that this will not be 100% accurate, since the xml generated
4035       by the response object can be different from the xml received,
4036       especially if there is some character set conversion involved, or such
4037       (eg. if you receive an empty string tag as &lt;string/&gt;, serialize()
4038       will output &lt;string&gt;&lt;/string&gt;), or if the server sent back
4039       as response something invalid (in which case the xml generated client
4040       side using serialize() will correspond to the error response generated
4041       internally by the lib).</para>
4042
4043       <para>2 - set the client object to return the raw xml received instead
4044       of the decoded objects:</para>
4045
4046       <programlisting language="php">
4047 $client = new xmlrpc_client($url);
4048 $client-&gt;return_type = 'xml';
4049 $resp = $client-&gt;send($msg);
4050 if (!$resp-&gt;faultCode())
4051   $data_to_be_saved = $resp-&gt;value();
4052 </programlisting>
4053
4054       <para>Note that using this method the xml response response will not be
4055       parsed at all by the library, only the http communication protocol will
4056       be checked. This means that xmlrpc responses sent by the server that
4057       would have generated an error response on the client (eg. malformed xml,
4058       responses that have faultcode set, etc...) now will not be flagged as
4059       invalid, and you might end up saving not valid xml but random
4060       junk...</para>
4061     </sect1>
4062
4063     <sect1>
4064       <title>Can I use the ms windows character set?</title>
4065
4066       <para>If the data your application is using comes from a Microsoft
4067       application, there are some chances that the character set used to
4068       encode it is CP1252 (the same might apply to data received from an
4069       external xmlrpc server/client, but it is quite rare to find xmlrpc
4070       toolkits that encode to CP1252 instead of UTF8). It is a character set
4071       which is "almost" compatible with ISO 8859-1, but for a few extra
4072       characters.</para>
4073
4074       <para>PHP-XMLRPC only supports the ISO 8859-1 and UTF8 character sets.
4075       The net result of this situation is that those extra characters will not
4076       be properly encoded, and will be received at the other end of the
4077       XML-RPC tranmission as "garbled data". Unfortunately the library cannot
4078       provide real support for CP1252 because of limitations in the PHP 4 xml
4079       parser. Luckily, we tried our best to support this character set anyway,
4080       and, since version 2.2.1, there is some form of support, left commented
4081       in the code.</para>
4082
4083       <para>To properly encode outgoing data that is natively in CP1252, you
4084       will have to uncomment all relative code in the file
4085       <filename>xmlrpc.inc</filename> (you can search for the string "1252"),
4086       then set <code>$GLOBALS['xmlrpc_internalencoding']='CP1252';</code>
4087       Please note that all incoming data will then be fed to your application
4088       as UTF-8 to avoid any potentail data loss.</para>
4089     </sect1>
4090
4091     <sect1>
4092       <title>Does the library support using cookies / http sessions?</title>
4093
4094       <para>In short: yes, but a little coding is needed to make it
4095       happen.</para>
4096
4097       <para>The code below uses sessions to e.g. let the client store a value
4098       on the server and retrieve it later.</para>
4099
4100       <para><programlisting>
4101 $resp = $client-&gt;send(new xmlrpcmsg('registervalue', array(new xmlrpcval('foo'), new xmlrpcval('bar'))));
4102 if (!$resp-&gt;faultCode())
4103 {
4104   $cookies = $resp-&gt;cookies();
4105   if (array_key_exists('PHPSESSID', $cookies)) // nb: make sure to use the correct session cookie name
4106   {
4107     $session_id = $cookies['PHPSESSID']['value'];
4108
4109     // do some other stuff here...
4110
4111     $client-&gt;setcookie('PHPSESSID', $session_id);
4112     $val = $client-&gt;send(new xmlrpcmsg('getvalue', array(new xmlrpcval('foo')));
4113   }
4114 }
4115 </programlisting>Server-side sessions are handled normally like in any other
4116       php application. Please see the php manual for more information about
4117       sessions.</para>
4118
4119       <para>NB: unlike web browsers, not all xmlrpc clients support usage of
4120       http cookies. If you have troubles with sessions and control only the
4121       server side of the communication, please check with the makers of the
4122       xmlrpc client in use.</para>
4123     </sect1>
4124   </chapter>
4125
4126   <appendix id="integration">
4127     <title>Integration with the PHP xmlrpc extension</title>
4128
4129     <para>To be documented more...</para>
4130
4131     <para>In short: for the fastest execution possible, you can enable the php
4132     native xmlrpc extension, and use it in conjunction with phpxmlrpc. The
4133     following code snippet gives an example of such integration</para>
4134
4135     <programlisting language="php">
4136 /*** client side ***/
4137 $c = new xmlrpc_client('http://phpxmlrpc.sourceforge.net/server.php');
4138
4139 // tell the client to return raw xml as response value
4140 $c-&gt;return_type = 'xml';
4141
4142 // let the native xmlrpc extension take care of encoding request parameters
4143 $r = $c-&gt;send(xmlrpc_encode_request('examples.getStateName', $_POST['stateno']));
4144
4145 if ($r-&gt;faultCode())
4146   // HTTP transport error
4147   echo 'Got error '.$r-&gt;faultCode();
4148 else
4149 {
4150   // HTTP request OK, but XML returned from server not parsed yet
4151   $v = xmlrpc_decode($r-&gt;value());
4152   // check if we got a valid xmlrpc response from server
4153   if ($v === NULL)
4154     echo 'Got invalid response';
4155   else
4156   // check if server sent a fault response
4157   if (xmlrpc_is_fault($v))
4158     echo 'Got xmlrpc fault '.$v['faultCode'];
4159   else
4160     echo'Got response: '.htmlentities($v);
4161 }
4162 </programlisting>
4163   </appendix>
4164
4165   <appendix id="substitution">
4166     <title>Substitution of the PHP xmlrpc extension</title>
4167
4168     <para>Yet another interesting situation is when you are using a ready-made
4169     php application, that provides support for the XMLRPC protocol via the
4170     native php xmlrpc extension, but the extension is not available on your
4171     php install (e.g. because of shared hosting constraints).</para>
4172
4173     <para>Since version 2.1, the PHP-XMLRPC library provides a compatibility
4174     layer that aims to be 100% compliant with the xmlrpc extension API. This
4175     means that any code written to run on the extension should obtain the
4176     exact same results, albeit using more resources and a longer processing
4177     time, using the PHP-XMLRPC library and the extension compatibility module.
4178     The module is part of the EXTRAS package, available as a separate download
4179     from the sourceforge.net website, since version 0.2</para>
4180   </appendix>
4181
4182   <appendix id="enough">
4183     <title>'Enough of xmlrpcvals!': new style library usage</title>
4184
4185     <para>To be documented...</para>
4186
4187     <para>In the meantime, see docs about xmlrpc_client::return_type and
4188     xmlrpc_server::functions_parameters_types, as well as php_xmlrpc_encode,
4189     php_xmlrpc_decode and php_xmlrpc_decode_xml</para>
4190   </appendix>
4191
4192   <appendix id="debugger">
4193     <title>Usage of the debugger</title>
4194
4195     <para>A webservice debugger is included in the library to help during
4196     development and testing.</para>
4197
4198     <para>The interface should be self-explicative enough to need little
4199     documentation.</para>
4200
4201     <para><graphic align="center" fileref="debugger.gif"
4202     format="GIF" /></para>
4203
4204     <para>The most useful feature of the debugger is without doubt the "Show
4205     debug info" option. It allows to have a screen dump of the complete http
4206     communication between client and server, including the http headers as
4207     well as the request and response payloads, and is invaluable when
4208     troubleshooting problems with charset encoding, authentication or http
4209     compression.</para>
4210
4211     <para>The debugger can take advantage of the JSONRPC library extension, to
4212     allow debugging of JSON-RPC webservices, and of the JS-XMLRPC library
4213     visual editor to allow easy mouse-driven construction of the payload for
4214     remote methods. Both components have to be downloaded separately from the
4215     sourceforge.net web pages and copied to the debugger directory to enable
4216     the extra functionality:</para>
4217
4218     <para><itemizedlist>
4219         <listitem>
4220           <para>to enable jsonrpc functionality, download the PHP-XMLRPC
4221           EXTRAS package, and copy the file <filename>jsonrpc.inc</filename>
4222           either to the same directory as the debugger or somewhere in your
4223           php include path</para>
4224         </listitem>
4225       </itemizedlist><itemizedlist>
4226         <listitem>
4227           <para>to enable the visual value editing dialog, download the
4228           JS-XMLRPC library, and copy somewhere in the web root files
4229           <filename>visualeditor.php</filename>,
4230           <filename>visualeditor.css</filename> and the folders
4231           <filename>yui</filename> and <filename>img</filename>. Then edit the
4232           debugger file <filename>controller.php</filename> and set
4233           appropriately the variable <varname>$editorpath</varname>.</para>
4234         </listitem>
4235       </itemizedlist></para>
4236   </appendix>
4237 </book>
4238 <!-- Keep this comment at the end of the file
4239 Local variables:
4240 mode: sgml
4241 sgml-omittag:nil
4242 sgml-shorttag:t
4243 sgml-minimize-attributes:nil
4244 sgml-always-quote-attributes:t
4245 sgml-indent-step:2
4246 sgml-indent-data:t
4247 sgml-parent-document:nil
4248 sgml-exposed-tags:nil
4249 sgml-local-catalogs:nil
4250 sgml-local-ecat-files:nil
4251 sgml-namecase-general:t
4252 sgml-general-insert-case:lower
4253 End:
4254 -->