Php xmlrcp client get rtorrent info

532 views Asked by At

I need to create simple php script for getting some information of my rtorrent instance ... i try a lot of code but i never give a responce ...

this is my last test

ini_set('display_errors', 1);
error_reporting(E_ALL);

function do_call($host, $port, $request) {

    $url = "http://$host:$port";
    $header[] = "Content-type: text/xml";
    $header[] = "Content-length: ".strlen($request);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

    $data = curl_exec($ch);
    if (curl_errno($ch)) {
        print curl_error($ch);
    } else {
        curl_close($ch);
        return $data;
    }
}

$host = '127.0.0.1';
$port = 10001;
$request = xmlrpc_encode_request("system.listMethods()", null);
$response = do_call($host, $port, $request);
var_dump($response);

Do you have simple working test code ?

1

There are 1 answers

0
Brad Cornford On

This is a bug within PHP-XMLRPC.

However you can replace your line:

$data = curl_exec($ch);

With:

$data = xmlrpc_decode(str_replace('i8>', 'i4>', curl_exec($ch)));

This should work as expected.