php resource centre

  • about
  • articles
  • tutorials
  • resources
  • certification
Home

Primary links

  • About
  • Articles
  • Tutorials
  • Resources
  • Certification

PHP XML-RPC Introduction

admin — Thu, 31/08/2006 - 11:09pm

What is XML-RPC?

RPC stands for Remote Procedure Call.

It is a set of specifications and implementations that makes applications running in different environments; different operating system can talk to each other by making remote procedure call. An RPC-based Web service is a collection of procedures that can be called by a remote client over the Internet. XML-RPC is the makes it easy for distributed systems and system interoperability. This allows a perl function to make a call to a Python method, or a Java Servlet to call a PHP function.



{mosgoogle}
This makes a lot for heterogenous applications can talk to each other with little support from programmers. So once it is set then application can talk to any RPC enabled application irrespective of its programming language and environment.

PHP supports RPC by providing rich set of functions and apis. These functions can be used to create server as well as client. You can find more information about RPC on http://xmlrpc.com and more documentation on this extension and its functions at http://xmlrpc-epi.sourceforge.net/.

As of PHP 4.1.0, the XML-RPC extension is included in the source package with the status of experimental. This extension is simply a copy of the XML-RPC EPI extension that can be found at http://xmlrpc-epi.sourceforge.net/main.php?t=php_about

How to enable XML-RPC extension on PHP?

XML-RPC support in PHP is not enabled by default. To enable it you need to uncomment the appropriate extension dll in php.ini( for Windows environment, as of PHP5.0.3 it would be ;extension=php_xmlrpc.dll and you need to make it extension=php_xmlrpc.dll by removing ;(comma)).

An XML-RPC call is sent from a client to a server via HTTP POST. This allows XML-RPC applications to work fairly easily behind firewalls, as port 80 is almost always open.

Example of Request and Response


Here's a sample XML-RPC request:

POST /default/php/server.php HTTP/1.0

User_Agent: This is a Dummy Client

Host: localhost

Content-Type: text/xml

Content-Length: 193

<?xml version="1.0" encoding="iso-8859-1"?>

<methodCall>

<methodName>dummyserver</methodName>

<params>

<param>

<value>

<string>test1</string>

</value>

</param>

</params>

</methodCall>

The first part of the request is simply a standard HTML post request. It's the data sent in the body of the request that interests us.The <methodCall> tags simply encapsulate the call, with all the parameters enclosed in <params> and each parameter enclosed in <param>. The data types supported in XML-RPC are:

<i4> or <int>

four-byte signed integer

10

<boolean>

0 (false) or 1 (true)

1

<string>

ASCII string

Hello, Mr. John

<double>

double-precision signed

floating point number

-21.2544

<dateTime.iso8601>

date/time

20011219T12:05:26

<base64>

base64-encoded binary

eW91IGNhbid0IHJlYWQgdGhpcyE=

In addition to the basic types, PHP also supports structs and arrays, <struct>s containing any number of <member>s that consist of <name>s and <value>s (specified in the same manner as <param>s):

<struct> <member> <name>name</name> <value> <string>Mr. John</string> </value> </member><member><name>title</name><value> <i4>Rodrigo</i4> </value></member></struct>

and arrays merely containing any number of <value>s:

<array>

<value><i4>10</i4></value>

<value><i4>20</i4></value>

<value><i4>30</i4></value>

</array>

Here's a sample XML-RPC response:

HTTP/1.1 200 OK

Date: Sat, 15 Jan 200516:24:16 GMT

Server: Apache/2.0.52 (Win32) PHP/5.0.3

X-Powered-By: PHP/5.0.3

Content-Length: 196

Connection: close

Content-Type: text/xml

<?xml version="1.0" encoding="iso-8859-1"?>

<methodResponse>

<params>

<param>

<value>

<string>Your request string contains test1.</string>

</value>

</param>

</params>

</methodResponse>

  • Tutorials
  • Login to post comments

User login

  • Request new password

Follow Us

Who's online

There are currently 0 users and 1 guest online.

Who's new

  • Nisha
  • linnaeus
  • Yameen
  • TalleyReedy
  • admin

Follow vipin7873 on Twitter

<!-- Start of Woopra Code -->

<!-- End of Woopra Code -->

  • about
  • articles
  • tutorials
  • resources
  • certification

copyright © 2010 Vipin Chandran