phpxml-rpc

How do I use the XML-RPC library?


How do I use the XML-RPC library in PHP 5.2.6 for an XML-RPC client? The server is in Python. I have xmlrpc-epi v 0.51 installed but the xmlrpc-epi-php examples section on the left showed me sf.net's version of a 404.


Solution

  • A very simple xmlrpc client, I use a cURL class, you can get it from: https://github.com/dcai/curl/blob/master/src/dcai/curl.php

    class xmlrpc_client {
        private $url;
        function __construct($url, $autoload=true) {
            $this->url = $url;
            $this->connection = new curl;
            $this->methods = array();
            if ($autoload) {
                $resp = $this->call('system.listMethods', null);
                $this->methods = $resp;
            }
        }
        public function call($method, $params = null) {
            $post = xmlrpc_encode_request($method, $params);
            return xmlrpc_decode($this->connection->post($this->url, $post));
        }
    }
    header('Content-Type: text/plain');
    $rpc = "http://10.0.0.10/api.php";
    $client = new xmlrpc_client($rpc, true);
    $resp = $client->call('methodname', array());
    print_r($resp);