mlandauer / phplib

Web Application component for Open Australia (phplib module)

This URL has Read+Write access

phplib / simplexmlrpc.php
100644 53 lines (44 sloc) 1.581 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/*
* simplexmlrpc.php:
* Simple wrapper around XMLRPC calls.
*
* Copyright (c) 2004 UK Citizens Online Democracy. All rights reserved.
* Email: chris@mysociety.org; WWW: http://www.mysociety.org/
*
* $Id: simplexmlrpc.php,v 1.2 2006/09/04 15:38:02 francis Exp $
*
*/
 
require_once('XML/RPC.php');
require_once('utility.php');
 
$sxr_clients = array( );
 
/* sxr_call HOST PORT PATH METHOD PARAMS
* Call, via the HTTP "proxy", HOST, PORT and PATH, the named METHOD, passing
* it the given PARAMS, which should be a single value or an array of values.
* Return whatever the method returns on success, or FALSE on failure. */
function sxr_call($host, $port, $path, $func, $params) {
    debug(XMLRPC, "SXR calling $func via http://$host:$port/$path");
    global $sxr_clients;
    $key = "$host:$port/$path";
    if (!array_key_exists($key, $sxr_clients))
        $sxr_clients[$key] = new XML_RPC_Client($path, $host, $port);
 
    $p = array();
    if (is_array($params)) {
        foreach ($params as $i) {
            array_push($p, XML_RPC_encode($i));
        }
    } else
        $p[0] = $params;
 
    $req = new XML_RPC_Message($func, $p);
    $resp = $sxr_clients[$key]->send($req);
 
    if ($resp->faultCode())
        return FALSE;
    else
        return XML_RPC_decode($resp->value());
}
 
/* sxr_call_idem HOST PORT PATH METHOD PARAMS
* As for sxr_call; but assumes that the result of any given call with specific
* parameters is unchanging, and so caches results from old queries. */
function sxr_call_idem($host, $port, $path, $func, $params) {
}
 
?>