Accessing geo-nick with Zend Framework (Zend_XmlRpc_Client)

Closing the tour of XML-RPC implementations usable with PHP-GTK, the shortest code to access our geo_nick service makes use a higher-level XML-RPC library: the Zend_XmlRpc_Client from the Zend Framework.

Unlike earlier implementations, Zend Framework (ZF) includes both the mashalling/unmarshalling to/from XML line format and the HTTP request/reponse process, wrapped up in a class-based mechanism using exceptions to handle errors, both at the HTTP and XML service levels (not demonstrated here).

if (!class_exists('gtk'))
"Please load the php-gtk2 module in your php.ini\r\n");


* Prepare the request data
$host    = '';
$port    = 80;
$backend = 'xmlrpc.php';

$client = new Zend_XmlRpc_Client("http://$host:$port/$backend");

$res = $client->call('gtkphpnet.geo_nick', '', 10);

* and display them in a PHP-GTK2 window
$window = new GtkWindow();
$window->set_title(' geo-nick service');
$window->connect_simple('destroy', array('Gtk','main_quit'));
$textBuffer = new GtkTextBuffer();
$textBuffer->set_text(print_r($res, true));

$textView   = new GtkTextView();


Of interest to PHP-GTK apps using more than one XML-RPC series of service is the notion of a server proxy available in ZF. This allows one to rewrite:

// ...
$client = new Zend_XmlRpc_Client("http://$host:$port/$backend");
$res = $client->call('gtkphpnet.geo_nick', '', 10);

as :

= new Zend_XmlRpc_Client("http://$host:$port/$backend");
$server = $client->getProxy('gtkphpnet');
$res = $server->geo_nick('', 10);

...which make XML-RPC calls almost like local calls, a bit like using a full SOAP stack without all the associated overhead.