05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Often a server will call xmlrpc_server_register_method( ) many times, to expose<br />

many functions.<br />

When you’ve registered all your methods, call xmlrpc_server_call_method( ) to do<br />

the dispatching:<br />

$response = xmlrpc_server_call_method(server, request, user_data [, options]);<br />

The request is the XML-RPC request, which is typically sent as HTTP POST data.<br />

We fetch that through the $HTTP_RAW_POST_DATA variable. It contains the name of the<br />

method to be called, and parameters to that method. The parameters are decoded<br />

into <strong>PHP</strong> data types, and the function (times( ), in this case) is called.<br />

A function exposed as an XML-RPC method takes two or three parameters:<br />

$retval = exposed_function(method, args [, user_data]);<br />

The method parameter contains the name of the XML-RPC method (so you can have<br />

one <strong>PHP</strong> function exposed under many names). The arguments to the method are<br />

passed in the array args, and the optional user_data parameter is whatever the<br />

xmlrpc_server_call_method( )’s user_data parameter was.<br />

The options parameter to xmlrpc_server_call_method( ) is an array mapping option<br />

names to their values. The options are:<br />

output_type<br />

Controls the data encoding used. Permissible values are: "php" or "xml" (default).<br />

verbosity<br />

Controls how much whitespace is added to the output XML to make it readable<br />

to humans. Permissible values are: "no_white_space", "newlines_only", and<br />

"pretty" (default).<br />

escaping<br />

Controls which characters are escaped, and how. Multiple values may be given<br />

as a subarray. Permissible values are: "cdata", "non-ascii" (default), "non-print"<br />

(default), and "markup" (default).<br />

versioning<br />

Controls which web service system to use. Permissible values are: "simple",<br />

"soap 1.1", "xmlrpc" (default for clients), and "auto" (default for servers, meaning<br />

“whatever format the request came in”).<br />

encoding<br />

Controls the character encoding of the data. Permissible values include any valid<br />

encoding identifiers, but you’ll rarely want to change it from "iso-8859-1" (the<br />

default).<br />

Clients<br />

An XML-RPC client issues an HTTP request and parses the response. The xmlrpc<br />

extension that ships with <strong>PHP</strong> can work with the XML that encodes an XML-RPC<br />

282 | Chapter 11: XML<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!