PHP
  Home arrow PHP arrow Page 5 - 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 
Moblin 
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 Server


    (Page 5 of 7 )

    In the XML-RPC world, you need a client and a server. The client is simply the application making the request, and the server is simply the service that processes the request and returns a response. In this section, we're looking at how to create an XML-RPC server service.

    PHP's XML-RPC extension has several methods that deal with servers, the most important being xmlrpc_server_create(), xmlrpc_server_register_method() and xmlrpc_server_call_method().

    xmlrpc_create_server() simply tells PHP that you would like to create a server.

    xmlrpc_server_register_method() registers PHP methods with the XML-RPC server so they may be called by a client.

    xmlrpc_server_call_method() is used for passing a request to the XML-RPC server and receiving a response.

    Nothing teaches like an example, so here you go (the comments in the example provide more details about the functions).

    <?php /* * First, we define some PHP functions to expose via * XML-RPC. Any functions that will be called by a * XML-RPC client need to take three parameters: * The first parameter passed is the name of the * XML-RPC method called, the second is an array * Containing the parameters sent by the client, and * The third is any data sent in the app_data * parameter of the xmlrpc_server_call_method() * function (see below). */ function uptime_func($method_name, $params, $app_data) { return `uptime`; } function greeting_func($method_name, $params, $app_data) { $name = $params[0]; return "Hello, $name. How are you today?"; } /* * This creates a server and sets a handle for the * server in the variable $xmlrpc_server */ $xmlrpc_server = xmlrpc_server_create(); /* * xmlrpc_server_register_method() registers a PHP * function as an XML-RPC method. It takes three * parameters: * The first is the handle of a server created with * xmlrpc_server_create(), the second is the name to * register the server under (this is what needs to * be in the <methodName> of a request for this * method), and the third is the name of the PHP * function to register. */ xmlrpc_server_register_method($xmlrpc_server, "greeting", "greeting_func"); xmlrpc_server_register_method($xmlrpc_server, "uptime", "uptime_func"); /* * When an XML-RPC request is sent to this script, it * can be found in the raw post data. */ $request_xml = $HTTP_RAW_POST_DATA; /* * The xmlrpc_server_call_method() sends a request to * the server and returns the response XML. In this case, * it sends the raw post data we got before. It requires * 3 arguments: * The first is the handle of a server created with * xmlrpc_server_create(), the second is a string containing * an XML-RPC request, and the third is for application data. * Whatever is passed into the third parameter of this function * is passed as the third paramater of the PHP function that the * request is asking for. */ $response = xmlrpc_server_call_method($xmlrpc_server, $request_xml, ''); // Now we print the response for the client to read. print $response; /* * This method frees the resources for the server specified * It takes one argument, a handle of a server created with * xmlrpc_server_create(). */ xmlrpc_server_destroy($xmlrpc_server); ?>

    More PHP Articles
    More By Lucas Marshall


     

       

    PHP ARTICLES

    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter
    - Building Your Own System Tray Application Us...
    - Structuring Your Projects for Web Applicatio...
    - Inserting, Updating and Deleting Database Ro...
    - Building Your Own Desktop Notepad Applicatio...
    - Web Application Security Overview
    - Working with the Active Record Class in Code...
    - Generate PDF Documents with PHP on the Windo...
    - Sending Email with PHP Networking
    - Performing Strict Validation with the Code I...
    - The preg_replace_callback() function in PHP





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