PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Method Calls

The constructor of Zend_XmlRpc_Client receives the URL of the remote XML-RPC server endpoint as its first parameter. The new instance returned may be used to call any number of remote methods at that endpoint.

To call a remote method with the XML-RPC client, instantiate it and use the call() instance method. The code sample below uses a demonstration XML-RPC server on the Zend Framework website. You can use it for testing or exploring the Zend_XmlRpc components.

Example 1060. XML-RPC Method Call

<?php
$client 
= new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');

echo 
$client->call('test.sayHello');

// hello

The XML-RPC value returned from the remote method call will be automatically unmarshaled and cast to the equivalent PHP native type. In the example above, a PHP String is returned and is immediately ready to be used.

The first parameter of the call() method receives the name of the remote method to call. If the remote method requires any parameters, these can be sent by supplying a second, optional parameter to call() with an Array of values to pass to the remote method:

Example 1061. XML-RPC Method Call with Parameters

<?php
$client 
= new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');

$arg1 1.1;
$arg2 'foo';

$result $client->call('test.sayHello', array($arg1$arg2));

// $result is a native PHP type

If the remote method doesn't require parameters, this optional parameter may either be left out or an empty array() passed to it. The array of parameters for the remote method can contain native PHP types, Zend_XmlRpc_Value objects, or a mix of each.

The call() method will automatically convert the XML-RPC response and return its equivalent PHP native type. A Zend_XmlRpc_Response object for the return value will also be available by calling the getLastResponse() method after the call.

Zend Framework