Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Before going deeply into the details of the PHP XML-RPC implementation, let's look at a short example that gives a good idea of what a simple client XML-RPC method invocation looks like. Example 5-1 shows an invocation of the method examples.getStateName that takes an int value and returns a string that contains the name of the corresponding U.S. state.
include("xmlrpc.inc");
$thestate=32;
$c=new xmlrpc_client("/RPC2", "betty.userland.com", 80);
$f=new xmlrpcmsg('examples.getStateName',
array(new xmlrpcval($thestate, "int")));
$r=$c->send($f);
$v=$r->value( );
if (!$r->faultCode( )) {
print "State number ". $thestate . " is " .
$v->scalarval( ) . "<br />";
print "<hr />I got this value back<br /><pre>" .
htmlentities($r->serialize( )). "</pre><hr />\n";
} else {
print "Fault: ";
print "Code: " . $r->faultCode( ) .
" Reason '" .$r->faultString( )."'<br />";
} |