PHP
  Home arrow PHP arrow Page 6 - Using XML-RPC with PHP
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Using XML-RPC with PHP
By: Lucas Marshall
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 28
    2001-12-20

    Table of Contents:
  • Using XML-RPC with PHP
  • Compiling PHP with XML-RPC Support
  • Dissection of a XML-RPC Call
  • Dissection of a XML-RPC Response
  • Creating an XML-RPC Server
  • Creating an XML-RPC Client
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using XML-RPC with PHP - Creating an XML-RPC Client


    (Page 6 of 7 )

    Now that we have a server, we need a client to call our methods. As mentioned before, the XML-RPC EPI extension for PHP does not make HTTP requests by itself. For that reason, before it was included in the PHP distribution, the XML-RPC EPI PHP extension came with some include files that had functions that make it a lot easier to work with XML-RPC requests.

    The only way to get these functions is to download the XML-RPC EPI PHP extension source package from http://xmlrpc-epi.sourceforge.net/, and install the files in the /sample/utils directory into a directory in your PHP include_path. For the purpose of the next pieces of example code, I will assume that you have copied the entire utils directory into a directory in your include_path, and renamed it xmlrpcutils.

    Making a client is fairly simple. The function that does all the work when we call our methods is xu_rpc_http_concise(), which is defined in the utils.php file of the xmlrpcutils directory now in our PHP include_path.

    First we'll make a client that calls the first method we defined in the server section of the article, the uptime method. This method does not require any parameters, so we won't pass any in. My comments about what we are doing and why will appear as comments in the code.

    <?php /* * This allows us to use the functions that make * making XML-RPC requests easy. */ include("xmlrpcutils/utils.php"); /* * For the next two lines use this guide. * If your server script can be found at the URL: * http://myhost.mydomain.com/xmlrpc_server.php * $host should be "myhost.mydomain.com" * and * $uri should be "/xmlrpc_server.php" */ // Change these to match your configuration $host = "myhost.mydomain.com"; $uri = "/xmlrpc_server.php"; /* * Here's where we make the request. xu_rpc_http_concise() * takes one parameter - a keyed array that specifies all * the info needed for the request. * The most important (and required) elements are: * 'method' - specifies the method to call * 'host' - specifies the host the server script is on * 'uri' - specifies the uri of the server script on the server * 'port' - specifies the port the server is listening on * * Here we are calling the uptime method of the * server script who's uri is specified in $uri of the * server that is at the hostname specified in $host and * listening on port 80 and storing it's response (converted * to a PHP data type) in $result. */ $result = xu_rpc_http_concise( array( 'method' => "uptime", 'host' => $host, 'uri' => $uri, 'port' => 80 ) ); print "The uptime on " . $host . " is " . $result; ?>
    When this is run it should print something like:
    The uptime on myhost.mydomain.com is 9:43pm up 5:12, 2 users, load average: 0.25, 0.24, 0.22
    Where the uptime numbers are the same as those you get if you run the 'uptime' command on the server running the server script.

    Our second example will call the greeting method. This is one that requires a parameter - a name.

    <?php include("xmlrpcutils/utils.php"); $host = "myhost.mydomain.com"; $uri = "/xmlrpc_server.php"; // Change this to your name $name = "yourname"; /* * The difference between this call and the last is we pass * in an array as the 'args' element of the array passed as * the argument of the xu_rpc_http_concise() function. */ $result = xu_rpc_http_concise( array( 'method' => "greeting", 'args' => array($name), 'host' => $host, 'uri' => $uri, 'port' => 80 ) ); print $result; ?>
    When run, this should print:

    Hello, yourname. How are you today?
    These are some very simple examples - xu_rpc_http_concise() can take some other arguments as well, and there are more functions available. I recommend that you read through the files in the xmlrpcutils directory to learn these for yourself.

    More PHP Articles
    More By Lucas Marshall


     

       

    PHP ARTICLES

    - Using Aliases and the Autoload Function with...
    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Sub Classing Exceptions in PHP 5
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT