05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

equest, but it doesn’t know how to issue HTTP requests. For that functionality, you<br />

must download the xmlrpc-epi distribution from http://xmlrpc-epi.sourceforge.net<br />

and install the sample/utils/utils.php file. This file contains a function to perform the<br />

HTTP request.<br />

Example 11-16 shows a client for the multiply XML-RPC service.<br />

Example 11-16. Basic XML-RPC client<br />

'xmlrpc');<br />

$result = xu_rpc_http_concise(<br />

array(method => 'multiply',<br />

args => array(5, 6),<br />

host => '192.168.0.1',<br />

uri => '/~gnat/test/ch11/xmlrpc-server.php',<br />

options => $options));<br />

echo "5 * 6 is $result";<br />

?><br />

We begin by loading the XML-RPC convenience utilities library. This gives us the<br />

xu_rpc_http_concise( ) function, which constructs a POST request for us:<br />

$response = xu_rpc_http_concise(hash);<br />

The hash array contains the various attributes of the XML-RPC call as an associative<br />

array:<br />

method<br />

Name of the method to call<br />

args<br />

Array of arguments to the method<br />

host<br />

Hostname of the web service offering the method<br />

uri<br />

URL path to the web service<br />

options<br />

Associative array of options, as for the server<br />

debug<br />

If nonzero, prints debugging information (default is 0)<br />

The value returned by xu_rpc_http_concise( ) is the decoded return value from the<br />

called method.<br />

There are several features of XML-RPC we haven’t covered. For example, XML-<br />

RPC’s data types do not always map precisely onto <strong>PHP</strong>’s, and there are ways to<br />

encode values as a particular data type rather than as the xmlrpc extension’s best<br />

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

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.<br />

Web Services | 283

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

Saved successfully!

Ooh no, something went wrong!