XML-RPC
XML-RPC and SOAP are two of the standard protocols used to create web services. XML-RPC is the older (and simpler) of the two, while SOAP is newer and more complex. Microsoft’s .NET initiative is based on SOAP, while many of the popular web journal packages, such as Frontier and Blogger, offer XML-RPC interfaces.
PHP provides access to both SOAP and XML-RPC through the
xmlrpc extension, which is based on the
xmlrpc-epi project (see http://xmlrpc-epi.sourceforge.net for more information).
The xmlrpc extension is not compiled in by default,
so you’ll need to add --with-xmlrpc to your configure line when you compile PHP.
Servers
Example 15-7 shows a very basic XML-RPC server that exposes only one
function (which XML-RPC calls a “method”). That function, multiply(), multiplies two numbers and returns
the result. It’s not a very exciting example, but it shows the basic
structure of an XML-RPC server.
Example 15-7. Multiplier XML-RPC server
<?php// expose this function via RPC as "multiply()"functiontimes($method,$args){return$args[0]*$args[1];}$request=$HTTP_RAW_POST_DATA;if(!$request){$requestXml=$_POST['xml'];}$server=xmlrpc_server_create()ordie("Couldn't create server");xmlrpc_server_register_method($server,"multiply","times");$options=array('output_type'=>'xml','version'=>'auto');echoxmlrpc_server_call_method($server,$request,null,$options);xmlrpc_server_destroy($server);
The xmlrpc extension handles the dispatch for you. That is, it ...
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.
Read now
Unlock full access