Feb 27

XML-RPC client with Horde

Tag: Horde, PHPOtaku @ 10:13

In Horde it is very easy to use webservices like XML-RPC.
This is a simple example of an XML-RPC request to a webservice located at http://rpc.example.com:8080

The signature of the webservice/method is:

Boolean setWebmailPassword(String username, String old_password, String new_password)
require_once 'Horde/RPC.php';
 
function setPassword($old_password, $new_password)
{
    global $notification;
 
    if (!isset($conf['xmlrpc']) || !isset($conf['xmlrpc']['server'])) {
        $conf['xmlrpc'] = array('server' => 'http://rpc.example.com:8080');
    }
 
    /* Build the xmlrpc request. */
    $response = Horde_RPC::request(
                'xmlrpc',
                $conf['xmlrpc']['server'],
                'setWebmailPassword',
                array(Auth::getAuth(),
                    $old_password,
                    $new_password                    )
                );
 
    if (is_a($response, 'PEAR_Error')) {
        Horde::logMessage(sprintf('setPassword(): %s failed', 'setPassword for '.Auth::getAuth()),
                      __FILE__, __LINE__, PEAR_LOG_ERR);
        $notification->push(_("This service is temporarily not available."), 'horde.error');
        return false;
    }
 
    /* Log the request at a DEBUG log level. */
    Horde::logMessage(sprintf('setPassword(): %s', 'setPassword for '.Auth::getAuth()),
                      __FILE__, __LINE__, PEAR_LOG_DEBUG);
 
    if (isset($response) && !is_a($response, 'PEAR_Error')) {
        return $response;
    } else {
        return false;
    }
 
}

Leave a Reply