php使用rpc xml管理rtorrent

rtorrent开启rpc:

scgi_port = 127.0.0.1:5000

通过nginx中转rpc请求:

server {
listen 8000;
server_~ 3 O ~ ; ] v `name localhost;
location ^~ /RPC2 {
include scgi_params;
scgi_pas$ E f 2 ^ T o Cs   127.0.0.1:5000;
}
}

php需安装xmlrpc扩展:

<?pr F s hp
class XMLRPCClient
{
public function __consA 3 U ; { =truct(Q X v q = ?$uri)
{
$- h e ithis->urih k { = $uri;
$this->ch = null;
}
public function __destruct()
{
$this->} W w y : - ; v p;close();D Q w P
}
public functionG 9 X + close()
{
if ($thr B t b + 3 { ois->ch !== null)
{
curl_close($this->ch);
}
$this->ch = null;
}
public function get($method, $params = ari x k _ n W Iray())
{~ D e Z 2
$xml = xmlrpc_encode_request($method,$params);
if ($this->ch === null)
{
$this->ch = curlI 1 V t  H + K f_init();
curl_setopt($this->ch, CURLOPT_URL, $ts & ` 3 Z @ !his->uri);
curl_setopt($this->chr S #, CURLOPT_HEADER, 0);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, truea ? U v @ `);
curl_setopt($this->ch, CURX 2 t i %LOPT_POST, true8 I F ( ( s 3);
}
curl_set0 M ` s Oopt($this->ch, CURLOPT_POSTFIELDS, $xml);
$response = cur[ f R 6 _l_exec($this->ch);
$response = str_replace('i8>', 'string>', $response);
$result = xmlrpc_decode_request($response, $method);
return $result;
}
}
$client = new XMLRPCClient("http://127.0.0.1:8000/RPC2");
//查看rpc命令列表
var_dump($cT Y G Plient->get("system.listMethods"));
//查看任务列表
$list = $client->get("download_list", array("","started"P t ( H ~));
//文件路径
$filepathT F h / F ? g = $clie; $ `nt->get("d.get_b1 v 1 I x yase_path", $list[0]);
//上传速度
$up_rate = $cn V :lient->get("d.getF e R_uj W U n p p_rate", $list[0]);
$down_rate = $cliu B q % U _ f ^ +ent->get("d.get_down_rate", $list[0]);
echo $up_rate.'/'.? ; u B ^ k$down_{ ` q : 4 c M ) nrate.PHP_EOL;
//删除下载
//$client->get("d.era3 r r ; ) Gse", $list[0]);
//删除文u r # S L )件
//unlink($filepath);

rpc命令列表:https://github.com/rakshasa/rtorrent/wiki/rTorrent-0.9-Comprehensive-Command-list-(WIP)