Skip to Content
PHP Cookbook
book

PHP Cookbook

by David Sklar, Adam Trachtenberg
November 2002
Intermediate to advanced
640 pages
16h 33m
English
O'Reilly Media, Inc.
Content preview from PHP Cookbook

12.6. Sending XML-RPC Requests

Problem

You want to be an XML-RPC client and make requests of a server. XML-RPC lets PHP make function calls to web servers, even if they don’t use PHP. The retrieved data is then automatically converted to PHP variables for use in your application.

Solution

Use PHP’s built-in XML-RPC extension with some helper functions. As of PHP 4.1, PHP bundles the xmlrpc-epi extension. Unfortunately, xmlrpc-epi does not have any native C functions for taking a XML-RPC formatted string and making a request. However, the folks behind xmlrpc-epi have a series of helper functions written in PHP available for download at http://xmlrpc-epi.sourceforge.net/xmlrpc_php/index.php. The only file used here is the one named index.php, which is located in xmlrpc_php/. To install it, just copy that file to a location where PHP can find it in its include_path.

Here’s some client code that calls a function on an XML-RPC server that returns state names:

// this is the default file name from the package // kept here to avoid confusion over the file name require 'utils.php'; // server settings $host = 'betty.userland.com'; $port = 80; $uri = '/RPC2'; // request settings // pass in a number from 1-50; get the nth state in alphabetical order // 1 is Alabama, 50 is Wyoming $method = 'examples.getStateName'; $args = array(32); // data to be passed // make associative array out of these variables $request = compact('host', 'port', 'uri', 'method', 'args'); // this function makes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
PHP Cookbook, 2nd Edition

PHP Cookbook, 2nd Edition

Adam Trachtenberg, David Sklar
PHP Cookbook, 3rd Edition

PHP Cookbook, 3rd Edition

David Sklar, Adam Trachtenberg
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe

Publisher Resources

ISBN: 1565926811Supplemental ContentCatalog PageErrata